Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert microseconds into a timestamp?

I took this piece from an unencrypted .DAT file:

Code:

00 e1 27 17 6f e6 69 c0

Which translates to 63,374,851,375,000,000 in decimal. The units for the number are microseconds.

And this huge number cannot bypass the 1st January 1970 00:00:00 format; such a format that most converters use today.

So, yes. Is there such a converter that uses the 1st January of the year 1 format? Or how shall I make one?

And by the way, a timestamp is both date and time.

Thanks in advance!

like image 998
Mark Avatar asked Mar 17 '26 21:03

Mark


1 Answers

You do not say what language are you using, if it is a .NET language, you can use: http://msdn.microsoft.com/en-us/library/z2xf7zzk.aspx for that constructor the input is in nanoseconds (are you sure that your number is in milliseconds and not in nanoseconds?).

If you are sure it is in milliseconds, the conversion to nanoseconds should be easy: 1 millisecond = 1 000 000 nanoseconds.

But I have the feeling that those are nanoseconds and not milliseconds...

Now that you have told us that it is in microseconds:

C# Example from decimal to yyyy dd MM hh:mm:ss


long microseconds = 63370738175000000;            
long ticks = microseconds * 10;
DateTime timestamp = new DateTime(ticks);
Console.WriteLine(timestamp.ToString("yyyy dd MM  hh:mm:ss"));

It prints:

2009 20 02 02:49:35

The other way around from yyyy dd MM hh:mm:ss to decimal


String dateString = "2009 20 02  02:49:35";
DateTime timestamp = DateTime.ParseExact(dateString, "yyyy dd MM  hh:mm:ss",CultureInfo.CurrentCulture);
long ticks = timestamp.Ticks;
long microseconds = ticks / 10;
Console.WriteLine(microseconds);

It prints:

63370694975000000

And if you want it in hexadecimal just write:


Console.WriteLine(microseconds.ToString("X"));

Then it will print:

E1234FB3278DC0

If you want the answer in another programming language, please add that to you question.

like image 92
Luxspes Avatar answered Mar 20 '26 21:03

Luxspes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!