Synchronizing dates between Java and C ++

I have an application that runs on a device that is not connected to the internet. OS - Windows XP. There is a C ++ module and a Java module that communicate over a socket. The Java part is to get the file from the C ++ part according to its date and time. When the DST switch appeared, they stopped working. It looks like C ++ is ignoring DST as Windows does not download the one-year DST update, and Java handles DST according to some internal table it has. The device I am programming must work continuously, unplugged and in different countries. My question is, how can I get Java and C ++ to ignore external updates and work according to some predefined DST.

+1


a source to share


3 answers


Encode the date as a string that includes time zone information ( ISO 8601 is the most comprehensive standard for this). Use good parsing frameworks to / from format on each side. Boost (C ++) and Joda (Java) provide great support for this.

Epoch time will not work for you as it does not represent a time zone.



If you need to adapt the timezone to do centralized work with it, then standardize to UTC and allow the client to adapt the date / time to their language for display purposes or for local manipulation. Otherwise, just store / retrieve the date / time in the local timezone if all manipulation and display is done in the local timezone.

+1


a source


Do you need to use a DST sensitive temporal representation? You could use Unix time (maybe this is what I could go with), TAI, or any other timestamp systems [some epochs] and no need to worry about things like daylight savings time or jump seconds ...



0


a source


I would advise you to use GMT + 0 to record the entire date and only adjust the time it is displayed.

0


a source







All Articles