Show the epoch

From Rosetta Code
Revision as of 21:49, 8 August 2011 by rosettacode>Kernigh (→‎{{header|Ruby}}: Fix lang tag.)
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.

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.

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

PowerShell

PowerShell uses .NET's DateTime structure and an integer can simply be casted appropriately:

<lang powershell>[datetime] 0</lang>

Output:

Monday, January 01, 0001 12:00:00 AM

Ruby

<lang ruby>irb(main):001:0> Time.at(0).utc => 1970-01-01 00:00:00 UTC</lang>