简体   繁体   English

如何在 c# 中将 integer 时间戳转换为 DateTime

[英]How to convert integer timestamp to DateTime in c#

I have a database file containing timestamp like "388740254860721408".我有一个包含时间戳的数据库文件,例如“388740254860721408”。 Unfortunately, I don't have a lot of documentation for the format.不幸的是,我没有很多关于这种格式的文档。 So I'm not sure how the timestamp is formatted.所以我不确定时间戳是如何格式化的。 How do I convert this number to a datetime?如何将此数字转换为日期时间?

Is this timestamp an actual value you found in the file?这个时间戳是您在文件中找到的实际值吗? The first thing that came to mind is UNIX timestamp.首先想到的是 UNIX 时间戳。 Either in milliseconds or in seconds.以毫秒或秒为单位。 For that big of a number I'd go with milliseconds, but It's invalid.对于这么大的数字,我会在几毫秒内使用 go,但它是无效的。

If in fact the UNIX milliseconds format is used to display this, the proper code for this is:如果实际上使用 UNIX 毫秒格式来显示它,那么正确的代码是:

var time = DateTimeOffset.FromUnixTimeMilliseconds(yourValue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM