Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable binary representation of date/time value

I am looking for a way to serialize date/time value in a binary file. However, the serialized presentation should be such that I must be able to deserialize it across platforms (Windows, Linux), architecture (64 bit/32 bit), and programming languages (C#, Java, C++). I am wondering if there are any public domain functions that are already available. Any pointer would be appreciated.

like image 578
Peter Avatar asked Oct 23 '25 05:10

Peter


2 Answers

Use 64-bit milliseconds since UNIX epoch. Should be good for a while ;-) (

like image 183
Steven Schlansker Avatar answered Oct 26 '25 20:10

Steven Schlansker


There are lots and lots of standards for dates and times. This webpage describes many of these formats. All of these formats can be serialized and deserialized to binary files. Many programming languages have functions that can import, export, and convert these formats.

If you are looking for a very small representation, then 32-bit or 64-bit seconds since a certain date and time might be a good choice. If you can live with a larger representation then you may want to store the date/time in one of the W3C DTF formats. For example the most detailed date/time looks like 1997-07-16T19:20:30.45+01:00.

like image 36
Nathan Farrington Avatar answered Oct 26 '25 22:10

Nathan Farrington