do you recognize a 16-digit timestamp?

情到浓时终转凉″ 提交于 2019-12-23 09:30:44

问题


Im working with Google bookmakrs and it returns 16-digit timestamp that i dont seem to be able to recognize in C# to turn into real dates, any ideas?

how to turn this timestamp: 1278276905502403 to something that makes sense in C#?


回答1:


That looks like UNIX time in microseconds. That is, the number of microseconds since 1970.01.01 00:00:00.

Could try something like:

dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddMilliseconds(value/1000);

(Probably a better way to do this, but I don't know C#.)

Python instead:

>>> time.ctime(1278276905502403/1000000)
'Sun Jul  4 22:55:05 2010'



回答2:


The timestamp is the number of microseconds since the epoch (01/01/1970 00:00:00 UTC).

You can convert it to a DateTime in C# like this:

var timestamp = 1278276905502403;
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var myDate = epoch.AddMilliseconds(timestamp / 1000);

The result for the example timestamp is: 07/04/2010 08:55:05 PM



来源:https://stackoverflow.com/questions/3219160/do-you-recognize-a-16-digit-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!