Show the epoch

Revision as of 19:10, 8 August 2011 by rosettacode>Mwn3d (Draft with Java)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Choose popular date libraries used by your language and show the epoch those libraries use. A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/whatever precision is used), but text from (with links to) documentation is also acceptable where a demonstration is impossible/impractical. For consistency's sake, show the date in UTC time where possible.

Show the epoch is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Java

DateFormat is needed to set the timezone. Printing date alone would show this date in the timezone/locale of the machine that the program is running on. The epoch used in java.util.Date is actually in GMT, but there isn't a significant difference between that and UTC for lots of applications (documentation for java.util.Date). <lang java>import java.text.DateFormat; import java.util.Date; import java.util.TimeZone;

public class DateTest{

   public static void main(String[] args) {
       Date date = new Date(0);
       DateFormat format = DateFormat.getDateTimeInstance();
       format.setTimeZone(TimeZone.getTimeZone("UTC"));
       System.out.println(format.format(date));
   }

}</lang> Output:

Jan 1, 1970 12:00:00 AM