Datetime 如何解析PRTG使用的时间戳
我有一个这种格式的日期时间字符串Datetime 如何解析PRTG使用的时间戳,datetime,go,timestamp,Datetime,Go,Timestamp,我有一个这种格式的日期时间字符串 44340.54166667但我想将其转换为5/24/2021 3:00:00 PM-4:00 PM格式。我怎么能用golang来解析呢?我尝试了一些转换函数,但没有成功。根据,PRTG使用的时间戳格式似乎定义为自1899年12月30日以来的天数 按照上述链接,以下Go代码应将时间戳转换为GoTime实例: prtg := 44340.5416666667 // substract number of days between Dec 30, 1899 and
44340.54166667
但我想将其转换为5/24/2021 3:00:00 PM-4:00 PM
格式。我怎么能用golang来解析呢?我尝试了一些转换函数,但没有成功。根据,PRTG使用的时间戳格式似乎定义为自1899年12月30日以来的天数
按照上述链接,以下Go代码应将时间戳转换为GoTime
实例:
prtg := 44340.5416666667
// substract number of days between Dec 30, 1899 and Jan 1, 1970 and convert to millis
millis := int64((prtg - 25569) * 86400 * 1000)
t := time.Unix(0, millis*int64(time.Millisecond))
println(t.Format("1/2/2006 03:04:05 PM"))
根据Gregor Zurowski评论中提到的,
将您的时间转换为纳秒
(时间的最小单位更精确),并添加1899-12-30 12.00午夜的unix nano。
将其重新转换为时间,并按如下格式设置格式
package main
import (
"fmt"
"time"
)
func main() {
startDate := time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC).UnixNano()
timeVar := 44340.5416666667 //your time variable
duration := startDate + int64(float64(24*60*60) * timeVar * 1e9) //duration since start date in nanoseconds
fmt.Println(time.Unix(0, duration).Format("1/2/2006 03:04:05 PM"))
}
什么是
44340.54166667
的意思?你能提到一些尝试过的方法来获得想法吗?我有一个来自返回api的xml响应5/24/2021 3:00:00 PM-4:00 PM 44340.5416666667
我想将第二行转换为第一行。是的,44340.5416666667
意味着什么?时间代表的是unix格式吗?或者以分钟、秒或类似的时间为单位?我猜这是《星际迷航》中的“星际约会”。它确实像一个!根据,此时间戳格式定义为自1899年12月30日起的天数值。