Show the epoch: Difference between revisions
(Draft with Java) |
(added PowerShell) |
||
Line 17: | Line 17: | ||
Output: |
Output: |
||
<pre>Jan 1, 1970 12:00:00 AM</pre> |
<pre>Jan 1, 1970 12:00:00 AM</pre> |
||
=={{header|PowerShell}}== |
|||
PowerShell uses .NET's <code>DateTime</code> structure and an integer can simply be casted appropriately: |
|||
<lang powershell>[datetime] 0</lang> |
|||
Output: |
|||
<pre>Monday, January 01, 0001 12:00:00 AM</pre> |
Revision as of 20:14, 8 August 2011
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