Convert a Java timestamp to C# DateTime object
-
Hi, i have a Java application that stores a timestamp object as a bigint in a MySql database. Now, my C# application has to convert it to a DateTime object. How do i do this. I tried using the Datetime.FromFileTime(timestamp); but the output it gives is not correct. Here is the sample.
long tm = 1217404627332; DateTime dt = DateTime.FromFileTime(tm); Response.Write("Time: " + dt.ToLongDateString());
The output it gives is Tuesday, January 02, 1601 when it should be Wednesday, July 31, 2008 How do i do this? Any help is appreciated. Thanks in advance.
-
Hi, i have a Java application that stores a timestamp object as a bigint in a MySql database. Now, my C# application has to convert it to a DateTime object. How do i do this. I tried using the Datetime.FromFileTime(timestamp); but the output it gives is not correct. Here is the sample.
long tm = 1217404627332; DateTime dt = DateTime.FromFileTime(tm); Response.Write("Time: " + dt.ToLongDateString());
The output it gives is Tuesday, January 02, 1601 when it should be Wednesday, July 31, 2008 How do i do this? Any help is appreciated. Thanks in advance.
One approach would be to search for how the number translates to a date in Java, and write code to do a conversion.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
Hi, i have a Java application that stores a timestamp object as a bigint in a MySql database. Now, my C# application has to convert it to a DateTime object. How do i do this. I tried using the Datetime.FromFileTime(timestamp); but the output it gives is not correct. Here is the sample.
long tm = 1217404627332; DateTime dt = DateTime.FromFileTime(tm); Response.Write("Time: " + dt.ToLongDateString());
The output it gives is Tuesday, January 02, 1601 when it should be Wednesday, July 31, 2008 How do i do this? Any help is appreciated. Thanks in advance.
The Windows FILETIME datatype, and hence .NET's DateTime, counts in 100ns intervals: there are 10 million of them in a single second. The base date is 1 January 1601. Your number, big though it is, only means 121,740 seconds or a little less than 34 hours. You need to find out how large a time interval one tick represents in your source data, and you need to find out what the base date is, so that you can manipulate it correctly for .NET.
DoEvents: Generating unexpected recursion since 1991
-
Hi, i have a Java application that stores a timestamp object as a bigint in a MySql database. Now, my C# application has to convert it to a DateTime object. How do i do this. I tried using the Datetime.FromFileTime(timestamp); but the output it gives is not correct. Here is the sample.
long tm = 1217404627332; DateTime dt = DateTime.FromFileTime(tm); Response.Write("Time: " + dt.ToLongDateString());
The output it gives is Tuesday, January 02, 1601 when it should be Wednesday, July 31, 2008 How do i do this? Any help is appreciated. Thanks in advance.
Java time represents milliseconds since January 1, 1970, so if you account for that date instead of the January 1601 date, you should be OK.
long tm = 1217404627332;
DateTime dt = new DateTime(1970,1,1,0,0,0);
dt = dt.AddMilliseconds(tm);
MessageBox.Show("Time: " + dt.ToLongDateString());HTH - although I get Wednesday July 30,2008....closer! -curtisk