From: Peter K on 2 Mar 2010 16:28 "Lothar Kimmeringer" <news200709(a)kimmeringer.de> wrote in message news:wctooysr657z.dlg(a)kimmeringer.de... > Peter K wrote: > >> Now I am writing a java application, which collects data and writes it to >> the database for the c# application to read. So how do I convert a java >> "Date" to a value which the c# application can interpret as "ticks"? > > Assuming that "ticks" are using NT Time, GIYF giving you e.g. > http://support.citrix.com/article/CTX109645 > > [...] > How to convert Windows NT Time to UNIX Time: > Divide by 10,000,000 and subtract 11,644,473,600. > How to convert UNIX Time to Windows NT Time: > Add 11,644,473,600 and multiply by 10,000,000. > [...] Thanks to all for your input. C# (.net) ticks are based on nanoseconds since 1/1/0001. Actually I had managed to write a satisfactory conversion routine - but during the testing I kept getting wrong answers, which turned out to be because I overlooked that Java months are 0-based while .net months are 1-based. (And timezones also confused the picture - most of the data is generated in a different timezone from where I am). At the moment I will keep the .net ticks as the value in the database. I understand it is not a generally accepted date/time representation, but the original software used this representation, and it seems the easiest to keep. Data can be input into the database from several sources (applications written in both c# and now in java). Data is read by a .net (c#) application. /Peter
From: Wojtek on 2 Mar 2010 19:40 Peter K wrote : > And timezones also confused the picture - most of the data is generated in a > different timezone from where I am And another good reason to always store dates in GMT -- Wojtek :-)
From: Roedy Green on 2 Mar 2010 20:56 On Tue, 2 Mar 2010 20:09:39 +1300, "Peter K" <peter(a)parcelvej.dk> wrote, quoted or indirectly quoted someone who said : > >Now I am writing a java application, which collects data and writes it to >the database for the c# application to read. So how do I convert a java >"Date" to a value which the c# application can interpret as "ticks"? There are so many definitions of "ticks". AT ticks were in the neighbourhood of 20 ms. Dates are just a wrapper around a long ms since 1970-01-01 You might have a look at the code in FileTimes http://mindprod.com/products.html#FILETIMES which interconverts between Java-ticks and MS file timestamp ticks. Java timestamps use 64-bit milliseconds since 1970 GMT. Windows timestamps use 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601, with ten thousand times as much precision. DIFF_IN_MILLIS is the difference between January 1 1601 and January 1 1970 in milliseconds. This magic number came from com.mindprod.common11.TestDate. Done according to Gregorian Calendar, no correction for 1752-09-02 Wednesday was followed immediately by 1752-09-14 Thursday dropping 12 days. Also according to http://gcc.gnu.org/ml/java-patches/2003-q1/msg00565.html private static final long DIFF_IN_MILLIS = 11644473600000L; long javaTime = ( msTime / 10000 ) - DIFF_IN_MILLIS; See http://mindprod.com/jgloss/time.html -- Roedy Green Canadian Mind Products http://mindprod.com The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair. ~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)
From: Arne Vajhøj on 2 Mar 2010 21:00 On 02-03-2010 20:56, Roedy Green wrote: > On Tue, 2 Mar 2010 20:09:39 +1300, "Peter K"<peter(a)parcelvej.dk> > wrote, quoted or indirectly quoted someone who said : >> Now I am writing a java application, which collects data and writes it to >> the database for the c# application to read. So how do I convert a java >> "Date" to a value which the c# application can interpret as "ticks"? > > There are so many definitions of "ticks". > > AT ticks were in the neighbourhood of 20 ms. > > Dates are just a wrapper around a long ms since 1970-01-01 > > You might have a look at the code in FileTimes > http://mindprod.com/products.html#FILETIMES > which interconverts between Java-ticks and MS file timestamp ticks. > > Java timestamps use 64-bit milliseconds since 1970 GMT. Windows > timestamps use 64-bit value representing the > number of 100-nanosecond intervals since January 1, 1601, with ten > thousand times as much precision. There are many definitions of ticks, but the original poster did say C# and in that case he must mean System.DateTime.Ticks and that is year 0001 based not 1601 based. Arne
From: Dr J R Stockton on 3 Mar 2010 17:56
In comp.lang.java.programmer message <qrfro5lqhcao7vsii7gmbbb6s8mrsjhogh @4ax.com>, Tue, 2 Mar 2010 17:56:20, Roedy Green <see_website(a)mindprod.c om.invalid> posted: >On Tue, 2 Mar 2010 20:09:39 +1300, "Peter K" <peter(a)parcelvej.dk> >wrote, quoted or indirectly quoted someone who said : > >> >>Now I am writing a java application, which collects data and writes it to >>the database for the c# application to read. So how do I convert a java >>"Date" to a value which the c# application can interpret as "ticks"? > > There are so many definitions of "ticks". > >AT ticks were in the neighbourhood of 20 ms. Exactly 0x1800B0 per 24-hour day; just over 0x10000 per hour; about 54.9 ms. > This magic number came from >com.mindprod.common11.TestDate. Done according to Gregorian Calendar, >no correction for 1752-09-02 Wednesday was followed immediately by >1752-09-14 Thursday dropping 12 days. Ten dates (no days) dropped. Later, parts of Canada dropped 11 dates. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc. |