views:

82

answers:

1

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!

A: 

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.

Luxspes
Also, make sure you know the "Zero Date" that you are using as an starting point.
Luxspes
Actually, it's microseconds, not milliseconds. My bad!
Mark
Ugh... my bad, it's My bad, guys. It's not milliseconds, it's microseconds.Okay, I'll put more timestamps:00 E1 23 59 C2 13 3D C0Outputs: 20/2/2009 14:49Decimal: 63370738175000000I've tried a converter Tool (from microseconds to year) using a 64 bit integer, and got a correct result which is 2009. However, I can't find any converter that does the same but from microseconds to timestamp (YYYY MM DD XX:XX:XX).
Mark
Well, then: 1 microsecond = 1000 nanoseconds. So you can still use .Net DateTime (again: What language/platform are you interested in?) all you have to do is to multiply your input parameter it by 1000.
Luxspes
I see now that .NET Ticks are 100 nanoseconds ( http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx ), and that means a single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond. And 1 tick equals 10 microseconds. So just mutiply 63370738175000000 by 10, and pass it as parameter get the correct conversion.
Luxspes
I added a C# example code to my answer that does the conversion correctly.
Luxspes
Thanks a lot... I've complied your example and it works :) I forget to say that my platform is visual basic (using by visual studio 2010) as it's easier for me. I'm trying to code a program that allows user to convert an inputted YYYY MM DD XX:XX:XX into decimal and then into hexadecimal
Mark
Mmmm, maybe I understood it incorrectly, but I thought that the idea was to convert from decimal in to YYYY MM DD XX:XX:XX (and the code I posted already does that) Do you also want a code the does the opposite operation?
Luxspes
Yes, that would be great. Hope you don't mind but... if it's possible for you to add a code that allows user input, that would be also great. :)
Mark
Thanks a lot again...
Mark
User input? isn't that out of the scope of the original question? (also there are many ways to get user input: WPF, WindowsForms, ASP.NET, Console, etc, etc. If you also need to know how to obtain user input, I think you should ask another question... don't you agree?
Luxspes
Thank you, Luxspes. I'd vote you up but it says I need 15 reps? Anyways, I accepted your answer :)
Mark
One more thing, my VS gives me an error 'CultureInfo' does not exist in the current context"
Mark
nvm i forgot to add using System.Globalization
Mark