我希望从指定的时区获得以秒为单位的偏移量。这正是Perl的Time::Zone中tz_offset()
所做的:“确定指定时区的GMT偏移量。”
Go中有没有办法做到这一点?输入是一个字符串,其时区名称为,就是,但我知道Go在LoadLocation()
包中有time
,因此 string =>偏移或 location =>抵消应该没问题。
输入:“MST”
输出: -25200
答案 0 :(得分:0)
这是代码,用于计算本地和指定时区之间的当前偏移量。我同意Ainar-G's comment,只有与指定的时刻有关,这种抵消才有意义:
<html>
<head>
<title>MY WEBSITE</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<?php include("title.php"); ?>
<?php
$googleadsensecode = ' //a function for the adsense code.
<div align="center"> //<div> to align the ad.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Responsive_TextnDisplay_20160127 -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-9232383262111727"
data-ad-slot="4287484293"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>';
echo $googeladsensecode;
</body>
</html>
答案 1 :(得分:0)
这应该可以解决问题:
location, err := time.LoadLocation("MST")
if err != nil {
panic(err)
}
tzName, tzOffset := time.Now().In(location).Zone()
fmt.Printf("name: [%v]\toffset: [%v]\n", tzName, tzOffset)
将打印:
名称:[MST]偏移:[-25200]