简体   繁体   中英

How to convert windows 64 bit timestamp to datetime?

I need to convert a windows hex 64 bit (big endian) date time to something readable in c#?

example '01cb17701e9c885a'

converts to "Tue, 29 June 2010 09:47:42 UTC"

Any help would be appreciated.

Looks like you need to parse this to long as hexadecimal and use FromFileTime to generate windows file time as a local and use ToUniversalTime to generate UTC equivalent.

long number = long.Parse("01cb17701e9c885a", NumberStyles.AllowHexSpecifier);
DateTime date = DateTime.FromFileTime(number).ToUniversalTime(); // 06/29/2010 09:47:42

or simpler, use FromFileTimeUtc as Matt mentioned;

DateTime date = DateTime.FromFileTimeUtc(number); // 06/29/2010 09:47:42

If you wanna get it as a string representation, you can use ToString method that DateTime instance with english-based culture (like InvariantCulture ) as;

string str = date.ToString("ddd, dd MMMM yyyy HH:mm:ss 'UTC'", 
                            CultureInfo.InvariantCulture);

Use DateTime.FromFileTimeUtc
For detail, visit this site

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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