What is the C# DateTimeOffset equivalent in Go

前端 未结 2 501
眼角桃花
眼角桃花 2021-01-17 04:13

I have the following code which takes a string as input which is converted into UNIX time stamp. I want to do the same in golang but I am not able to recognize the struct or

2条回答
  •  悲哀的现实
    2021-01-17 04:42

    For example,

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func TimeFromTicks(ticks int64) time.Time {
        base := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix()
        return time.Unix(ticks/10000000+base, ticks%10000000).UTC()
    }
    
    func main() {
        fmt.Println(TimeFromTicks(635804753769100000))
    }
    

    Output:

    2015-10-15 03:09:36.0091 +0000 UTC
    

提交回复
热议问题