在尝试解析时区时正确使用时区
在解析时间区域代码时,至关重要的是,对于go中的时间范围的范围pars pars pars parsean parsean pars pars parsean the parsean the pars parse parse是至关重要的。缩写为论点。但是,无论您指定的时区如何,该函数的输出始终为“ 05:00:00 0000 UTC”。出现问题,因为您正在当前位置中解析时间,这可能与所需的时区有所不同。 go's Time.parse函数假设您在当前位置进行解析,除非使用Time.Location明确指定。
fun fun code fun code fun code func func: parseandprintWithLocation(现在是Time.Time,TimeZone String){ 位置,err:= time.loadlocation(时区) 如果err!= nil { fmt.println(err) 返回 } 测试,err:= time.parseinlocation(“ 15:04:05 mst”,fmt.sprintf(“ 05:00:00”,TimeZone),位置) 如果err!= nil { fmt.println(err) 返回 } 测试=时间。 现在。年(), now.month(), now.day(), test.hour(), test.minute(), test.second(), test.nansecond(), test.location(), ) fmt.println(测试) }
通过使用时区位置使用正确的方法,您可以确保按比例的时间反映所需的时区,从而允许您的代码准确地处理不同区域的时间。免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3