什么是C#的DateTimeOffset相当于围棋

编程入门 行业动态 更新时间:2024-10-25 01:30:00
本文介绍了什么是C#的DateTimeOffset相当于围棋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有下面的代码,它接受一个字符串作为输入被转换成UNIX时间戳。我想要做相同的golang但我不能够识别的结构或功能,这将给围棋的DateTimeOffset结构的等效。

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 function which will give an equivalent of DateTimeOffset structure in Go.

class Program { static void Main(string[] args) { var date = GetUtcTimestampFromAttribute(); Console.WriteLine(date); if (date != null) { Console.WriteLine(ToUnixTimeStamp(date.Value)); } Console.ReadKey(); } public static DateTimeOffset? GetUtcTimestampFromAttribute() { var ticks = long.Parse("7036640000000"); Console.WriteLine(ticks); return GetUtcTimestampFromTicks(ticks); } public static DateTimeOffset? GetUtcTimestampFromTicks(long ticks) { Console.WriteLine(new DateTimeOffset(ticks, TimeSpan.Zero)); return ticks != 0 ? new DateTimeOffset(ticks, TimeSpan.Zero) : (DateTimeOffset?)null; } public static long ToUnixTimeStamp(DateTimeOffset timeStamp) { var epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); return Convert.ToInt64((timeStamp - epoch).TotalSeconds); } }

例如:

输入:635804753769100000

Input: 635804753769100000

输出:1444878577

Output: 1444878577

相应时间在UTC:10 /二千零十五​​分之十五上午03点09分36秒+00:00

Corresponding Time in UTC : 10/15/2015 3:09:36 AM +00:00

有人可以帮我上一种变通方法,以获得上述结果。

Can someone please help me on a workaround to get the above result.

感谢

推荐答案

例如,

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)) }

输出:

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

更多推荐

什么是C#的DateTimeOffset相当于围棋

本文发布于:2023-11-09 23:04:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573679.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:围棋   DateTimeOffset

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!