Show the epoch: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added Wren)
m (→‎{{header|Wren}}: Minor tidy)
 
(20 intermediate revisions by 15 users not shown)
Line 14: Line 14:


=={{header|ABAP}}==
=={{header|ABAP}}==
<lang ABAP>DATA: lv_date TYPE datum.
<syntaxhighlight lang="abap">DATA: lv_date TYPE datum.


lv_date = 0.
lv_date = 0.


WRITE: / lv_date.
WRITE: / lv_date.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 25: Line 25:
</pre>
</pre>
===Simplified===
===Simplified===
<lang ABAP>cl_demo_output=>display( |Result: { CONV datum( 0 ) }| ).
<syntaxhighlight lang="abap">cl_demo_output=>display( |Result: { CONV datum( 0 ) }| ).
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 36: Line 36:


However, conversion from unix epoch seconds is also supported and shown below.
However, conversion from unix epoch seconds is also supported and shown below.
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
Line 44: Line 44:
begin
begin
Put_Line (Image (Date => etime));
Put_Line (Image (Date => etime));
end ShowEpoch;</lang>
end ShowEpoch;</syntaxhighlight>
{{out}}
{{out}}
<pre>1970-01-01 00:00:00</pre>
<pre>1970-01-01 00:00:00</pre>

=={{header|AppleScript}}==

There are no fewer than three epochs associated with Mac OS. The original was 1st January 1904 00:00:00. This is stated in the 1999 AppleScript Language Guide, but I don't recall there ever having been a way to find it out by script and I don't think time zone was considered. Mac OS X was introduced in 2001 with a "Cocoa" framework whose epoch was the first instant (UTC) of that year and "underlying UNIX functionality". The <tt>do shell script</tt> added to AppleScript later that year made it possible for scripts to discover the Unix epoch. Since Mac OS X 10.9 (for library scripts) and Mac OS 10.10 (for running scripts), AppleScript's been able to access parts of the Cocoa system without needing add-ons and is thereby able to get the Cocoa epoch.

<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions

local CocoaEpoch, UnixEpoch

-- Get the date 0 seconds from the Cocoa epoch.
set CocoaEpoch to current application's class "NSDate"'s dateWithTimeIntervalSinceReferenceDate:(0)
-- The way it's rendered in its 'description' is good enough for the current purpose.
set CocoaEpoch to CocoaEpoch's |description|() as text

-- Get the date 0 seconds from the Unix epoch and format it in the same way.
set UnixEpoch to (do shell script "date -ur 0 '+%F %T %z'")

return "Cocoa epoch: " & CocoaEpoch & linefeed & "Unix epoch: " & UnixEpoch</syntaxhighlight>

{{output}}
<syntaxhighlight lang="applescript">"Cocoa epoch: 2001-01-01 00:00:00 +0000
Unix epoch: 1970-01-01 00:00:00 +0000"</syntaxhighlight>

=={{header|Arturo}}==

<syntaxhighlight lang="rebol">print to :date 0 ; convert UNIX timestamp: 0 to date

print now
print to :integer now ; convert current date to UNIX timestamp</syntaxhighlight>

{{out}}

<pre>1970-01-01T01:00:00+01:00
2021-05-22T09:27:18+02:00
1621668438</pre>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SHOW_THE_EPOCH.AWK
# syntax: GAWK -f SHOW_THE_EPOCH.AWK
# requires GNU Awk 4.0.1 or later
# requires GNU Awk 4.0.1 or later
Line 56: Line 93:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 64: Line 101:
=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> INSTALL @lib$+"DATELIB"
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"DATELIB"
PRINT FN_date$(0, "dd-MMM-yyyy")</lang>
PRINT FN_date$(0, "dd-MMM-yyyy")</syntaxhighlight>
'''Output:'''
'''Output:'''
<pre>
<pre>
Line 72: Line 109:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <time.h>
<syntaxhighlight lang="c">#include <time.h>
#include <stdio.h>
#include <stdio.h>


Line 79: Line 116:
printf("%s", asctime(gmtime(&t)));
printf("%s", asctime(gmtime(&t)));
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>
Line 85: Line 122:
FileTime, from the Win32 API, uses a different epoch.
FileTime, from the Win32 API, uses a different epoch.
{{libheader|Win32}}
{{libheader|Win32}}
<lang c>#include <windows.h>
<syntaxhighlight lang="c">#include <windows.h>
#include <stdio.h>
#include <stdio.h>
#include <wchar.h>
#include <wchar.h>
Line 118: Line 155:
wprintf(L"FileTime epoch is %ls, at %ls (UTC).\n", date, time);
wprintf(L"FileTime epoch is %ls, at %ls (UTC).\n", date, time);
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>FileTime epoch is Monday, January 01, 1601, at 12:00:00 AM (UTC).</pre>
<pre>FileTime epoch is Monday, January 01, 1601, at 12:00:00 AM (UTC).</pre>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program
class Program
Line 131: Line 168:
Console.WriteLine(new DateTime());
Console.WriteLine(new DateTime());
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1-1-0001 0:00:00</pre>
<pre>1-1-0001 0:00:00</pre>
Line 139: Line 176:
{{works with|gcc|4.5.3}}
{{works with|gcc|4.5.3}}
Doesn't work with MSVC 10 SP1
Doesn't work with MSVC 10 SP1
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <chrono>
#include <chrono>
#include <ctime>
#include <ctime>
Line 148: Line 185:
std::cout << std::asctime(std::gmtime(&t)) << '\n';
std::cout << std::asctime(std::gmtime(&t)) << '\n';
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>
{{libheader|boost}}
{{libheader|boost}}
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <boost/date_time.hpp>
#include <boost/date_time.hpp>
int main()
int main()
Line 158: Line 195:
std::cout << boost::posix_time::ptime( boost::posix_time::min_date_time ) << '\n';
std::cout << boost::posix_time::ptime( boost::posix_time::min_date_time ) << '\n';
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1400-Jan-01 00:00:00</pre>
<pre>1400-Jan-01 00:00:00</pre>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(println (java.util.Date. 0))</lang>
<syntaxhighlight lang="clojure">(println (java.util.Date. 0))</syntaxhighlight>
Output (since Clojure 1.5)
Output (since Clojure 1.5)
<lang>#inst "1970-01-01T00:00:00.000-00:00"</lang>
<syntaxhighlight lang="text">#inst "1970-01-01T00:00:00.000-00:00"</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. epoch.
PROGRAM-ID. epoch.


Line 184: Line 221:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


{{out}}
{{out}}
Line 190: Line 227:


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
<lang coffeescript>console.log new Date(0).toISOString()</lang>
<syntaxhighlight lang="coffeescript">console.log new Date(0).toISOString()</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 GMT</pre>
<pre>Thu, 01 Jan 1970 00:00:00 GMT</pre>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>(multiple-value-bind (second minute hour day month year) (decode-universal-time 0 0)
<syntaxhighlight lang="lisp">(multiple-value-bind (second minute hour day month year) (decode-universal-time 0 0)
(format t "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" year month day hour minute second))</lang>
(format t "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" year month day hour minute second))</syntaxhighlight>
{{out}}
{{out}}
<pre>1900-01-01 00:00:00</pre>
<pre>1900-01-01 00:00:00</pre>
Line 204: Line 241:


=={{header|Dart}}==
=={{header|Dart}}==
<lang dart>main() {
<syntaxhighlight lang="dart">main() {
print(new Date.fromEpoch(0,new TimeZone.utc()));
print(new Date.fromEpoch(0,new TimeZone.utc()));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1970-01-01 00:00:00.000Z</pre>
<pre>1970-01-01 00:00:00.000Z</pre>


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang Delphi>program ShowEpoch;
<syntaxhighlight lang="delphi">program ShowEpoch;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 219: Line 256:
begin
begin
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>1899-12-30 00:00:00.000</pre>
<pre>1899-12-30 00:00:00.000</pre>
Line 238: Line 275:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>printfn "%s" ((new System.DateTime()).ToString("u"))</lang>
<syntaxhighlight lang="fsharp">printfn "%s" ((new System.DateTime()).ToString("u"))</syntaxhighlight>
{{out}}
{{out}}
<pre>0001-01-01 00:00:00Z</pre>
<pre>0001-01-01 00:00:00Z</pre>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: calendar calendar.format io ;
<syntaxhighlight lang="factor">USING: calendar calendar.format io ;


0 micros>timestamp timestamp>ymdhms print</lang>
0 micros>timestamp timestamp>ymdhms print</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 253: Line 290:
=={{header|Forth}}==
=={{header|Forth}}==
{{works with|4tH|3.61.3}}
{{works with|4tH|3.61.3}}
<lang forth>include lib/longjday.4th
<syntaxhighlight lang="forth">include lib/longjday.4th
0 posix>jday .longjday cr</lang>
0 posix>jday .longjday cr</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 269: Line 306:


Date/time values in FB are always based on the current regional settings and so, if values are needed for other time-zones (or UTC), the appropriate adjustments must be made.
Date/time values in FB are always based on the current regional settings and so, if values are needed for other time-zones (or UTC), the appropriate adjustments must be made.
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


#Include "vbcompat.bi"
#Include "vbcompat.bi"
Line 284: Line 321:
Print
Print
Print "Press any key to quit"
Print "Press any key to quit"
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 294: Line 331:
December 17, 1680 00:00:00
December 17, 1680 00:00:00
</pre>
</pre>

=={{header|Frink}}==
Internally, Frink references all date/time values as a number of seconds relative to Julian Day 0 referenced to UTC. The internal numeric type is Frink's "do the right thing" numeric type which can be exact rational numbers, arbitrary-precision floating-point numbers, or even intervals, which gives essentially arbitrary precision and exact round-trip capability to any date/time value stored. These are transparently converted to arbitrary timezones or date systems for display.
<syntaxhighlight lang="frink">println[ JD[0 s] -> UTC ]</syntaxhighlight>
{{out}}
<pre>
BC 4713-01-01 PM 12:00:00.000 (Mon) Coordinated Universal Time
</pre>
Frink also makes it easy to work with date/time values referenced to any arbitrary epoch. For example, to find the number of nanoseconds since the UNIX epoch:
<syntaxhighlight lang="frink">epoch = # 1970 UTC #
now[] - epoch -> ns
</syntaxhighlight>
{{out}}
<pre>
1665439770353000000
</pre>
Or to add a number of seconds to the UNIX epoch and find the result in Japan's timezone:
<syntaxhighlight lang="frink">epoch = # 1970 UTC #
epoch + 2 billion seconds -> Japan
</syntaxhighlight>
{{out}}
<pre>
AD 2033-05-18 PM 12:33:20.000 (Wed) Japan Standard Time
</pre>

Leap seconds are usually not taken into account in these calculations, but they can be easily using [https://frinklang.org/#LeapSeconds Frink's leap-second functions.]


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>
<syntaxhighlight lang="futurebasic">window 1
include "ConsoleWindow"


print date$
print date$
Line 312: Line 374:
print
print
print time$("h:mm a ZZZZ "); date$("MMMM d, yyyy G")
print time$("h:mm a ZZZZ "); date$("MMMM d, yyyy G")

</lang>
HandleEvents</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 331: Line 394:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main
import ("fmt"; "time")
import ("fmt"; "time")


func main() {
func main() {
fmt.Println(time.Time{})
fmt.Println(time.Time{})
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
This is UNIX format. The 1 on the end is the full year, not two or four digit year.
This is UNIX format. The 1 on the end is the full year, not two or four digit year.
Line 345: Line 408:
=={{header|Groovy}}==
=={{header|Groovy}}==
Groovy uses the UNIX epoch.
Groovy uses the UNIX epoch.
<lang groovy>def date = new Date(0)
<syntaxhighlight lang="groovy">def date = new Date(0)
def format = new java.text.SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ')
def format = new java.text.SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ')
format.timeZone = TimeZone.getTimeZone('UTC')
format.timeZone = TimeZone.getTimeZone('UTC')
println (format.format(date))</lang>
println (format.format(date))</syntaxhighlight>
{{out}}
{{out}}
<pre>1970-01-01T00:00:00.000+0000</pre>
<pre>1970-01-01T00:00:00.000+0000</pre>
Line 356: Line 419:
The <code>ClockTime</code> type is abstract in Haskell 98, but is defined in GHC.
The <code>ClockTime</code> type is abstract in Haskell 98, but is defined in GHC.
{{works with|GHC}}
{{works with|GHC}}
<lang haskell>import System.Time
<syntaxhighlight lang="haskell">import System.Time


main = putStrLn $ calendarTimeToString $ toUTCTime $ TOD 0 0</lang>
main = putStrLn $ calendarTimeToString $ toUTCTime $ TOD 0 0</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 UTC 1970</pre>
<pre>Thu Jan 1 00:00:00 UTC 1970</pre>
===New time library===
===New time library===
{{works with|GHC}}
{{works with|GHC}}
<lang haskell>import Data.Time
<syntaxhighlight lang="haskell">import Data.Time


main = print $ UTCTime (ModifiedJulianDay 0) 0</lang>
main = print $ UTCTime (ModifiedJulianDay 0) 0</syntaxhighlight>
{{out}}
{{out}}
<pre>1858-11-17 00:00:00 UTC</pre>
<pre>1858-11-17 00:00:00 UTC</pre>
Line 381: Line 444:
* [http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime routines] use a global variable 'DateBaseYear' which defaults to Jan 1, 1970 00:00:00 but can be set if desired.
* [http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime routines] use a global variable 'DateBaseYear' which defaults to Jan 1, 1970 00:00:00 but can be set if desired.
* The example below uses only a couple of the datetime procedures
* The example below uses only a couple of the datetime procedures
<lang Unicon>link printf,datetime
<syntaxhighlight lang="unicon">link printf,datetime


procedure main()
procedure main()
Line 392: Line 455:
now := DateToSec(&date) + ClockToSec(&clock)
now := DateToSec(&date) + ClockToSec(&clock)
printf("Now is also %s and %s\n",SecToDate(now),SecToDateLine(now))
printf("Now is also %s and %s\n",SecToDate(now),SecToDateLine(now))
end</lang>
end</syntaxhighlight>
{{out|Sample Output}}
{{out|Sample Output}}
<pre>&now and gettimeofday().sec are equal
<pre>&now and gettimeofday().sec are equal
Line 401: Line 464:
=={{header|J}}==
=={{header|J}}==
J does not have an epoch. J's native representation of date and time is a six element list: year, month, day, hour, minute, second. For example:
J does not have an epoch. J's native representation of date and time is a six element list: year, month, day, hour, minute, second. For example:
<lang j> 6!:0''
<syntaxhighlight lang="j"> 6!:0''
2011 8 8 20 25 44.725</lang>
2011 8 8 20 25 44.725</syntaxhighlight>
(August 8, 2011, 8:25:44 pm)
(August 8, 2011, 8:25:44 pm)


That said, the <code>'dates'</code> library does have an epoch:
That said, the <code>'dates'</code> library does have an epoch:
<lang j> require'dates'
<syntaxhighlight lang="j"> require'dates'
todate 0
todate 0
1800 1 1</lang>
1800 1 1</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<code>DateFormat</code> is needed to set the timezone. Printing <code>date</code> alone would show this date in the timezone/locale of the machine that the program is running on. The epoch used in <code>java.util.Date</code> (as well as <code>java.sql.Date</code>, which can be subbed into this example) is actually in GMT, but there isn't a significant difference between that and UTC for lots of applications ([http://download.oracle.com/javase/7/docs/api/java/util/Date.html#getTime() documentation for java.util.Date]).
<code>DateFormat</code> is needed to set the timezone. Printing <code>date</code> alone would show this date in the timezone/locale of the machine that the program is running on. The epoch used in <code>java.util.Date</code> (as well as <code>java.sql.Date</code>, which can be subbed into this example) is actually in GMT, but there isn't a significant difference between that and UTC for lots of applications ([http://download.oracle.com/javase/7/docs/api/java/util/Date.html#getTime() documentation for java.util.Date]).
<lang java>import java.text.DateFormat;
<syntaxhighlight lang="java">import java.text.DateFormat;
import java.util.Date;
import java.util.Date;
import java.util.TimeZone;
import java.util.TimeZone;
Line 423: Line 486:
System.out.println(format.format(date));
System.out.println(format.format(date));
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Jan 1, 1970 12:00:00 AM</pre>
<pre>Jan 1, 1970 12:00:00 AM</pre>
On my PC I see
On my PC I see
<pre>01.01.1970 00:00:00</pre>
<pre>01.01.1970 00:00:00</pre>

===Using Java 8===
Java 8 introduced the classes LocalDate, LocalTime, LoclDateTime,
and other associated classes which simplified the manipulation of dates and times.
<syntaxhighlight lang = "java">
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public final class ShowTheEpoch {

public static void main(String[] args) {
System.out.println(LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC));
}

}

</syntaxhighlight>
{{ out }}
<pre>
1970-01-01T00:00
</pre>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>document.write(new Date(0).toUTCString());</lang>
<syntaxhighlight lang="javascript">document.write(new Date(0).toUTCString());</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 GMT</pre>
<pre>Thu, 01 Jan 1970 00:00:00 GMT</pre>

=={{header|Joy}}==
<syntaxhighlight lang="joy">0 gmtime "%Y-%m-%d %H:%M:%S" strftime.</syntaxhighlight>
{{out}}
<pre>"1970-01-01 00:00:00"</pre>


=={{header|jq}}==
=={{header|jq}}==
<lang jq>0 | todate</lang>
<syntaxhighlight lang="jq">0 | todate</syntaxhighlight>
{{out}}
{{out}}
<lang sh>"1970-01-01T00:00:00Z"</lang>
<syntaxhighlight lang="sh">"1970-01-01T00:00:00Z"</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>using Base.Dates # just using Dates in versions > 0.6
<syntaxhighlight lang="julia">using Base.Dates # just using Dates in versions > 0.6
println("Time zero (the epoch) is $(unix2datetime(0)).")</lang>
println("Time zero (the epoch) is $(unix2datetime(0)).")</syntaxhighlight>


{{out}}
{{out}}
Line 450: Line 539:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>// version 1.1.2
<syntaxhighlight lang="scala">// version 1.1.2


import java.util.Date
import java.util.Date
Line 461: Line 550:
format.timeZone = TimeZone.getTimeZone("UTC")
format.timeZone = TimeZone.getTimeZone("UTC")
println(format.format(epoch))
println(format.format(epoch))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 469: Line 558:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>date(0.00)
<syntaxhighlight lang="lasso">date(0.00)
date(0)</lang>
date(0)</syntaxhighlight>


{{out}}
{{out}}
Line 477: Line 566:


=={{header|Limbo}}==
=={{header|Limbo}}==
<lang Limbo>implement Epoch;
<syntaxhighlight lang="limbo">implement Epoch;


include "sys.m"; sys: Sys;
include "sys.m"; sys: Sys;
Line 493: Line 582:
daytime = load Daytime Daytime->PATH;
daytime = load Daytime Daytime->PATH;
sys->print("%s\n", daytime->text(daytime->gmt(0)));
sys->print("%s\n", daytime->text(daytime->gmt(0)));
}</lang>
}</syntaxhighlight>


Of course, this could also be done by mangling the namespace and forging the current date, locking it to the epoch:
Of course, this could also be done by mangling the namespace and forging the current date, locking it to the epoch:


<lang Limbo>implement Epoch;
<syntaxhighlight lang="limbo">implement Epoch;


include "sys.m"; sys: Sys;
include "sys.m"; sys: Sys;
Line 531: Line 620:
sys->print("%s\n", daytime->text(daytime->gmt(daytime->now())));
sys->print("%s\n", daytime->text(daytime->gmt(daytime->now())));
}
}
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 541: Line 630:
Lingo's date object is not based on an epoch, but instead on runtime date calculations. A new date object is created by specifying "year, month, day", based on gregorian calendar. In arithmetic context, date objects are casted to "days" (AD), not to seconds or milliseconds (see below).
Lingo's date object is not based on an epoch, but instead on runtime date calculations. A new date object is created by specifying "year, month, day", based on gregorian calendar. In arithmetic context, date objects are casted to "days" (AD), not to seconds or milliseconds (see below).


<lang Lingo>now = the systemDate
<syntaxhighlight lang="lingo">now = the systemDate
put now
put now
-- date( 2018, 3, 21 )
-- date( 2018, 3, 21 )
Line 549: Line 638:
-- print approx. year difference between "babylonianDate" and now
-- print approx. year difference between "babylonianDate" and now
put (now-babylonianDate)/365.2425
put (now-babylonianDate)/365.2425
-- 3818.1355</lang>
-- 3818.1355</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
LiveCode uses midnight, January 1, 1970 as the start of the eon
LiveCode uses midnight, January 1, 1970 as the start of the eon
<lang LiveCode>put 0 into somedate
<syntaxhighlight lang="livecode">put 0 into somedate
convert somedate to internet date
convert somedate to internet date
put somedate
put somedate
Line 559: Line 648:
-- output GMT (localised)
-- output GMT (localised)
-- Thu, 1 Jan 1970 10:00:00 +1000
-- Thu, 1 Jan 1970 10:00:00 +1000
</syntaxhighlight>
</lang>


=={{header|LotusScript}}==
=={{header|LotusScript}}==
Uses LotusScript to calculate difference between current time and epoch start date. This example: a button which prints the result. Of course, change the <code>timeStamp</code> variable to whatever suits your need.
Uses LotusScript to calculate difference between current time and epoch start date. This example: a button which prints the result. Of course, change the <code>timeStamp</code> variable to whatever suits your need.


<lang lotusscript>
<syntaxhighlight lang="lotusscript">
Sub Click(Source As Button)
Sub Click(Source As Button)
'Create timestamp as of now
'Create timestamp as of now
Line 582: Line 671:


End Sub
End Sub
</syntaxhighlight>
</lang>


Output:
Output:
Line 590: Line 679:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>print(os.date("%c", 0))</lang>
<syntaxhighlight lang="lua">print(os.date("%c", 0))</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>


=={{header|Mathematica}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>DateString[0]</lang>
<syntaxhighlight lang="mathematica">DateString[0]</syntaxhighlight>
{{out}}
->Mon 1 Jan 1900 00:00:00
<pre>Mon 1 Jan 1900 00:00:00</pre>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Matlab and Octave store date/time number in a floating point number counting the days.
Matlab and Octave store date/time number in a floating point number counting the days.
<lang matlab>d = [0,1,2,3.5,-3.5,1000*365,1000*366,now+[-1,0,1]];
<syntaxhighlight lang="matlab">d = [0,1,2,3.5,-3.5,1000*365,1000*366,now+[-1,0,1]];
for k=1:length(d)
for k=1:length(d)
printf('day %f\t%s\n',d(k),datestr(d(k),0))
printf('day %f\t%s\n',d(k),datestr(d(k),0))
disp(datevec(d(k)))
disp(datevec(d(k)))
end;</lang>
end;</syntaxhighlight>
{{out}}
{{out}}
<pre>day 0.000000 31-Dec--001 00:00:00
<pre>day 0.000000 31-Dec--001 00:00:00
Line 631: Line 721:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>timedate(0);
<syntaxhighlight lang="maxima">timedate(0);
"1900-01-01 10:00:00+10:00"</lang>
"1900-01-01 10:00:00+10:00"</syntaxhighlight>

=={{header|min}}==
<syntaxhighlight lang="min">0 datetime puts!</syntaxhighlight>
{{out}}
<pre>
1970-01-01T00:00:00Z
</pre>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
{{trans|Java}}
{{trans|Java}}
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary


Line 646: Line 743:
say zulu.format(edate)
say zulu.format(edate)
return
return
</syntaxhighlight>
</lang>
'''Output:'''
'''Output:'''
<pre>
<pre>
Line 653: Line 750:


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>(date 0)
<syntaxhighlight lang="newlisp">(date 0)
->"Thu Jan 01 01:00:00 1970"</lang>
->"Thu Jan 01 01:00:00 1970"</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
Nim “times” module provides procedures to convert to and from timestamps. Using these procedures, it’s easy to find the epoch, even on another system:
<lang nim>import times
<syntaxhighlight lang="nim">import times


echo "Epoch for Posix systems: ", fromUnix(0).utc
echo getGMTime(fromSeconds(0))</lang>
echo "Epoch for Windows system: ", fromWinTime(0).utc</syntaxhighlight>
Output:

<pre>Thu Jan 1 00:00:00 1970</pre>
{{out}}
<pre>Epoch for Posix systems: 1970-01-01T00:00:00Z
Epoch for Windows system: 1601-01-01T00:00:00Z</pre>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
<lang objc>#import <Foundation/Foundation.h>
<syntaxhighlight lang="objc">#import <Foundation/Foundation.h>


int main(int argc, const char *argv[]) {
int main(int argc, const char *argv[]) {
Line 677: Line 778:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out|Log}}
{{out|Log}}
<pre>2001-01-01 00:00:00 +0000</pre>
<pre>2001-01-01 00:00:00 +0000</pre>


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>open Unix
<syntaxhighlight lang="ocaml">open Unix


let months = [| "January"; "February"; "March"; "April"; "May"; "June";
let months = [| "January"; "February"; "March"; "April"; "May"; "June";
Line 689: Line 790:
let () =
let () =
let t = Unix.gmtime 0.0 in
let t = Unix.gmtime 0.0 in
Printf.printf "%s %d, %d\n" months.(t.tm_mon) t.tm_mday (1900 + t.tm_year)</lang>
Printf.printf "%s %d, %d\n" months.(t.tm_mon) t.tm_mday (1900 + t.tm_year)</syntaxhighlight>
{{out|Execution}}
{{out|Execution}}
<pre>$ ocaml unix.cma epoch.ml
<pre>$ ocaml unix.cma epoch.ml
Line 696: Line 797:
=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>import: date
<syntaxhighlight lang="oforth">import: date


0 asDateUTC println</lang>
0 asDateUTC println</syntaxhighlight>


{{out}}
{{out}}
Line 707: Line 808:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
GP has no built-in date or time system.
GP has no built-in date or time system.
<lang parigp>system("date -ur 0")</lang>
<syntaxhighlight lang="parigp">system("date -ur 0")</syntaxhighlight>


PARI, as usual, has access to the same resources as [[#C|C]].
PARI, as usual, has access to the same resources as [[#C|C]].
Line 713: Line 814:
=={{header|Pascal}}==
=={{header|Pascal}}==
This works with [[Free_Pascal| Free Pascal]]:
This works with [[Free_Pascal| Free Pascal]]:
<lang pascal>Program ShowEpoch;
<syntaxhighlight lang="pascal">Program ShowEpoch;


uses
uses
Line 721: Line 822:
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now));
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now));
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 730: Line 831:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>print scalar gmtime 0, "\n";</lang>
<syntaxhighlight lang="perl">print scalar gmtime 0, "\n";</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>
Line 736: Line 837:
=={{header|Phix}}==
=={{header|Phix}}==
The standard Phix file builtins/datetime.e does not use an epoch, but instead expects absolute values, eg Jan 1st 1970 is {1970,1,1,...}. I suppose the closest we can get is:
The standard Phix file builtins/datetime.e does not use an epoch, but instead expects absolute values, eg Jan 1st 1970 is {1970,1,1,...}. I suppose the closest we can get is:
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>constant d0 = {0,1,1,0,0,0,1,1}
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
include builtins\timedate.e
<span style="color: #008080;">constant</span> <span style="color: #000000;">d0</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span>
?format_timedate(d0,"YYYY-MM-DD")
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
?format_timedate(d0,"Dddd, Mmmm d, YYYY")</lang>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d0</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d0</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Dddd, Mmmm d, YYYY"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
<pre>
<pre>
"0000-01-01"
"0000-01-01"
Line 748: Line 852:


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php
echo gmdate('r', 0), "\n";
echo gmdate('r', 0), "\n";
?></lang>
?></syntaxhighlight>
{{out}}
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 +0000</pre>
<pre>Thu, 01 Jan 1970 00:00:00 +0000</pre>
Line 756: Line 860:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
The 'date' function in PicoLisp returns a day number, starting first of March of the year zero. Calculated according to the gregorian calendar (despite that that calendar wasn't used in 0 AD yet).
The 'date' function in PicoLisp returns a day number, starting first of March of the year zero. Calculated according to the gregorian calendar (despite that that calendar wasn't used in 0 AD yet).
<lang PicoLisp>: (date 1)
<syntaxhighlight lang="picolisp">: (date 1)
-> (0 3 1) # Year zero, March 1st</lang>
-> (0 3 1) # Year zero, March 1st</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
The usual localtime() method for simple time extraction is available, but the built in Calendar module is a more diverse tool.
The usual localtime() method for simple time extraction is available, but the built in Calendar module is a more diverse tool.
<syntaxhighlight lang="pike">
<lang Pike>
object cal = Calendar.ISO->set_timezone("UTC");
object cal = Calendar.ISO->set_timezone("UTC");
write( cal.Second(0)->format_iso_short() );
write( cal.Second(0)->format_iso_short() );
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>19700101T00:00:00</pre>
<pre>19700101T00:00:00</pre>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>*process source attributes xref;
<syntaxhighlight lang="pli">*process source attributes xref;
epoch: Proc Options(main);
epoch: Proc Options(main);
/*********************************************************************
/*********************************************************************
Line 785: Line 889:
Put Edit(d ,days(d))
Put Edit(d ,days(d))
(Skip,a,f(15));
(Skip,a,f(15));
End;</lang>
End;</syntaxhighlight>
Result:
Result:
<pre>
<pre>
Line 798: Line 902:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
PowerShell uses .NET's <code>DateTime</code> structure and an integer can simply be casted appropriately:
PowerShell uses .NET's <code>DateTime</code> structure and an integer can simply be casted appropriately:
<lang powershell>[datetime] 0</lang>
<syntaxhighlight lang="powershell">[datetime] 0</syntaxhighlight>
{{out}}
{{out}}
<pre>Monday, January 01, 0001 12:00:00 AM</pre>
<pre>Monday, January 01, 0001 12:00:00 AM</pre>
Line 804: Line 908:
===Three Alternates===
===Three Alternates===
<code>Get-Date</code> always returns its '''Kind''' property as Local:
<code>Get-Date</code> always returns its '''Kind''' property as Local:
<syntaxhighlight lang="powershell">
<lang PowerShell>
Get-Date -Year 1 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0 -Millisecond 0
Get-Date -Year 1 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0 -Millisecond 0
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 812: Line 916:
</pre>
</pre>
This approach returns its '''Kind''' property as Unspecified:
This approach returns its '''Kind''' property as Unspecified:
<syntaxhighlight lang="powershell">
<lang PowerShell>
New-Object -TypeName System.DateTime
New-Object -TypeName System.DateTime
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 821: Line 925:
Here you could describe the epoch date's '''Kind''' property as being Utc.
Here you could describe the epoch date's '''Kind''' property as being Utc.
Formatting the output as a list for demonstration:
Formatting the output as a list for demonstration:
<syntaxhighlight lang="powershell">
<lang PowerShell>
New-Object -TypeName System.DateTime -ArgumentList 1, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc) | Format-List
New-Object -TypeName System.DateTime -ArgumentList 1, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc) | Format-List
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 843: Line 947:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang purebasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()
PrintN(FormatDate("Y = %yyyy M = %mm D = %dd, %hh:%ii:%ss", 0))
PrintN(FormatDate("Y = %yyyy M = %mm D = %dd, %hh:%ii:%ss", 0))
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre>Y = 1970 M = 01 D = 01, 00:00:00</pre>
<pre>Y = 1970 M = 01 D = 01, 00:00:00</pre>


=={{header|Python}}==
=={{header|Python}}==
<lang python>>>> import time
<syntaxhighlight lang="python">>>> import time
>>> time.asctime(time.gmtime(0))
>>> time.asctime(time.gmtime(0))
'Thu Jan 1 00:00:00 1970'
'Thu Jan 1 00:00:00 1970'
>>></lang>
>>></syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang R>> epoch <- 0
<syntaxhighlight lang="r">> epoch <- 0
> class(epoch) <- class(Sys.time())
> class(epoch) <- class(Sys.time())
> format(epoch, "%Y-%m-%d %H:%M:%S %Z")
> format(epoch, "%Y-%m-%d %H:%M:%S %Z")
[1] "1970-01-01 00:00:00 UTC"</lang>
[1] "1970-01-01 00:00:00 UTC"</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(require racket/date)
(require racket/date)
(date->string (seconds->date 0 #f))
(date->string (seconds->date 0 #f))
</syntaxhighlight>
</lang>


Output:
Output:
Line 878: Line 982:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>say DateTime.new(0)</lang>
<syntaxhighlight lang="raku" line>say DateTime.new(0)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 886: Line 990:
=={{header|REXX}}==
=={{header|REXX}}==
The epoch for the REXX language BIF &nbsp; (<u>B</u>uilt-<u>I</u>n <u>F</u>unction) &nbsp; '''DATE''' &nbsp; is: &nbsp; January 1st, year 1.
The epoch for the REXX language BIF &nbsp; (<u>B</u>uilt-<u>I</u>n <u>F</u>unction) &nbsp; '''DATE''' &nbsp; is: &nbsp; January 1st, year 1.
<lang rexx>/*REXX program displays the number of days since the epoch for the DATE function (BIF). */
<syntaxhighlight lang="rexx">/*REXX program displays the number of days since the epoch for the DATE function (BIF). */


say ' today is: ' date() /*today's is format: mm MON YYYY */
say ' today is: ' date() /*today's is format: mm MON YYYY */
Line 896: Line 1,000:
/* ↑ ┌───◄─── This BIF (Built-In Function) is only */
/* ↑ ┌───◄─── This BIF (Built-In Function) is only */
/* └─────────◄──────┘ for newer versions of REXX that */
/* └─────────◄──────┘ for newer versions of REXX that */
/* support the 2nd and 3rd arguments. */</lang>
/* support the 2nd and 3rd arguments. */</syntaxhighlight>
{{output|out}}
{{output|out}}
<pre>
<pre>
Line 905: Line 1,009:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "guilib.ring"
load "guilib.ring"


Line 920: Line 1,024:
exec()
exec()
}
}
</syntaxhighlight>
</lang>
Output:
Output:
[[File:CalmoSoftShowEpoch.jpg]]
[[File:CalmoSoftShowEpoch.jpg]]

=={{header|RPL}}==
RPL can not go back into the past beyond 15 October 1582.
15.101582 -1 DATE+
{{out}}
<pre>
DATE+ Error:
Bad Argument Value
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>irb(main):001:0> Time.at(0).utc
<syntaxhighlight lang="ruby">irb(main):001:0> Time.at(0).utc
=> 1970-01-01 00:00:00 UTC</lang>
=> 1970-01-01 00:00:00 UTC</syntaxhighlight>
The Date class however uses the Julian date -4712-1-1 as default when no parameters are supplied
The Date class however uses the Julian date -4712-1-1 as default when no parameters are supplied
<lang ruby>require "date"
<syntaxhighlight lang="ruby">require "date"
Date.new # => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)>
Date.new # => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)>
</syntaxhighlight>
</lang>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>eDate$ = date$("01/01/0001")
<syntaxhighlight lang="runbasic">eDate$ = date$("01/01/0001")
cDate$ = date$(0) ' 01/01/1901
cDate$ = date$(0) ' 01/01/1901
sDate$ = date$("01/01/1970")</lang>
sDate$ = date$("01/01/1970")</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==


<lang rust>extern crate time;
<syntaxhighlight lang="rust">extern crate time;


use time::{at_utc, Timespec};
use time::{at_utc, Timespec};
Line 946: Line 1,059:
let epoch = at_utc(Timespec::new(0, 0));
let epoch = at_utc(Timespec::new(0, 0));
println!("{}", epoch.asctime());
println!("{}", epoch.asctime());
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>import java.util.{Date, TimeZone, Locale}
<syntaxhighlight lang="scala">import java.util.{Date, TimeZone, Locale}
import java.text.DateFormat
import java.text.DateFormat


val df=DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.ENGLISH)
val df=DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.ENGLISH)
df.setTimeZone(TimeZone.getTimeZone("UTC"))
df.setTimeZone(TimeZone.getTimeZone("UTC"))
println(df.format(new Date(0)))</lang>
println(df.format(new Date(0)))</syntaxhighlight>
{{out}}
{{out}}
<pre>January 1, 1970 12:00:00 AM UTC</pre>
<pre>January 1, 1970 12:00:00 AM UTC</pre>
=={{header|Scheme}}==
{{works with|Chez Scheme}}
<syntaxhighlight lang="scheme">; Display date at Time Zero in UTC.
(printf "~s~%" (time-utc->date (make-time 'time-utc 0 0) 0))</syntaxhighlight>
{{out}}
<pre>
#<date Thu Jan 1 00:00:00 1970>
</pre>


=={{header|Seed7}}==
=={{header|Seed7}}==
Line 968: Line 1,089:
negative years exist and that the year preceding 1 is 0.
negative years exist and that the year preceding 1 is 0.
Therefore the epoch is the beginning of the year 0.
Therefore the epoch is the beginning of the year 0.
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
include "time.s7i";


Line 974: Line 1,095:
begin
begin
writeln(time.value);
writeln(time.value);
end func;</lang>
end func;</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 981: Line 1,102:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>say Time.new(0).gmtime.ctime;</lang>
<syntaxhighlight lang="ruby">say Time.new(0).gmtime.ctime;</syntaxhighlight>
{{out}}
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
<pre>Thu Jan 1 00:00:00 1970</pre>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>- Date.toString (Date.fromTimeUniv Time.zeroTime);
<syntaxhighlight lang="sml">- Date.toString (Date.fromTimeUniv Time.zeroTime);
val it = "Thu Jan 1 00:00:00 1970" : string</lang>
val it = "Thu Jan 1 00:00:00 1970" : string</syntaxhighlight>


=={{header|Stata}}==
=={{header|Stata}}==
<lang stata>. di %td 0
<syntaxhighlight lang="stata">. di %td 0
01jan1960
01jan1960
. di %tc 0
. di %tc 0
01jan1960 00:00:00</lang>
01jan1960 00:00:00</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>% clock format 0 -gmt 1
<syntaxhighlight lang="tcl">% clock format 0 -gmt 1
Thu Jan 01 00:00:00 GMT 1970</lang>
Thu Jan 01 00:00:00 GMT 1970</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE TUSCRIPT
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
- epoch
- epoch
number=1
number=1
Line 1,009: Line 1,130:
dayofweeknr=DATE (today,day,month,year,number)
dayofweeknr=DATE (today,day,month,year,number)
date=JOIN (year,"-",month,day)
date=JOIN (year,"-",month,day)
PRINT "today's date: ", date," (daynumber ", number,")"</lang>
PRINT "today's date: ", date," (daynumber ", number,")"</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,016: Line 1,137:
</pre>
</pre>


=={{header|uBasic/4tH}}==
uBasic/4tH provides a '''TIME()''' function, which returns the common epoch, but doesn't provide a builtin function to display it - other than it's numerical value. This program shows the epoch in high level code.
<syntaxhighlight lang="text">Print Show(FUNC(_DateStr(0))), Show(FUNC(_TimeStr(0)))
End

_DateStr ' convert epoch to date string
Param (1)
Local (6)

a@ = a@ / 86400 ' just get the number of days since epoch
b@ = 1970+(a@/365) ' ball parking year, will not be accurate!

d@ = 0
For c@ = 1972 To b@ - 1 Step 4
If (((c@%4) = 0) * ((c@%100) # 0)) + ((c@%400) = 0) Then d@ = d@+1
Next

b@ = 1970+((a@ - d@)/365) ' calculating accurate current year by (x - extra leap days)
e@ = ((a@ - d@)%365)+1 ' if current year is leap, set indicator to 1
f@ = (((b@%4) = 0) * ((b@%100) # 0)) + ((b@%400) = 0)

g@ = 0 ' calculating current month
For c@ = 0 To 11 Until e@ < (g@+1)
g@ = g@ + FUNC(_Monthdays (c@, f@))
Next
' calculating current date
g@ = g@ - FUNC(_Monthdays (c@-1, f@))
' Print a@, d@, e@, f@
Return (Join (Str(b@), FUNC(_Format (c@, Dup("-"))), FUNC(_Format (e@ - g@, Dup("-")))))

_TimeStr ' convert epoch to time string
Param (1)
Return (Join(Str((a@%86400)/3600), FUNC(_Format ((a@%3600)/60, Dup(":"))), FUNC(_Format (a@%60, Dup(":")))))

_Format Param (2) : Return (Join (Iif (a@<10, Join(b@, "0"), b@), Str (a@)))
_Monthdays Param (2) : Return (((a@ + (a@<7)) % 2) + 30 - ((2 - b@) * (a@=1)))</syntaxhighlight>
{{Out}}
<pre>
1970-01-01 0:00:00

0 OK, 0:58
</pre>
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
The nonstandard option <code>date -r</code> takes seconds from the epoch, and prints date and time. See [http://www.openbsd.org/cgi-bin/man.cgi?query=date&apropos=0&sektion=1&manpath=OpenBSD+Current&arch=i386&format=html date(1) manual].
The nonstandard option <code>date -r</code> takes seconds from the epoch, and prints date and time. See [http://www.openbsd.org/cgi-bin/man.cgi?query=date&apropos=0&sektion=1&manpath=OpenBSD+Current&arch=i386&format=html date(1) manual].
{{works with|OpenBSD}}
{{works with|OpenBSD}}
<lang bash>$ date -ur 0
<syntaxhighlight lang="bash">$ date -ur 0
Thu Jan 1 00:00:00 UTC 1970</lang>
Thu Jan 1 00:00:00 UTC 1970</syntaxhighlight>


On systems with GNU date, you can do
On systems with GNU date, you can do
<lang bash>
<syntaxhighlight lang="bash">
$ TZ=UTC date --date "$(date +%s) seconds ago"
$ TZ=UTC date --date "$(date +%s) seconds ago"
Thu Jan 1 00:00:00 UTC 1970
Thu Jan 1 00:00:00 UTC 1970
</syntaxhighlight>
</lang>


=={{header|Visual Basic}}==
=={{header|Visual Basic}}==
<lang vb>Sub Main()
<syntaxhighlight lang="vb">Sub Main()
Debug.Print Format(0, "dd mmm yyyy hh:mm")
Debug.Print Format(0, "dd mmm yyyy hh:mm")
End Sub</lang>
End Sub</syntaxhighlight>
{{out|Output (in debug window)}}
{{out|Output (in debug window)}}
30 Dec 1899 00:00
30 Dec 1899 00:00
Line 1,038: Line 1,201:
{{libheader|Wren-date}}
{{libheader|Wren-date}}
The epoch (or zero date/time) for the above module is midnight on 1st January, 0001 UTC according to the Gregorian proleptic calendar, though it can also cater for the Unix epoch as well.
The epoch (or zero date/time) for the above module is midnight on 1st January, 0001 UTC according to the Gregorian proleptic calendar, though it can also cater for the Unix epoch as well.
<lang ecmascript>import "/date" for Date
<syntaxhighlight lang="wren">import "./date" for Date


Date.default = Date.isoFull
Date.default = Date.isoFull
Line 1,045: Line 1,208:


var dt2 = Date.unixEpoch
var dt2 = Date.unixEpoch
System.print(dt2)</lang>
System.print(dt2)</syntaxhighlight>


{{out}}
{{out}}
Line 1,055: Line 1,218:
=={{header|zkl}}==
=={{header|zkl}}==
Using the method tickToTock(time_t,useLocalTime) on Linux. tickToTock converts a time_t (seconds since the epoch) to "human" time. False means use UTC (vs local time, the default).
Using the method tickToTock(time_t,useLocalTime) on Linux. tickToTock converts a time_t (seconds since the epoch) to "human" time. False means use UTC (vs local time, the default).
<lang zkl>zkl: Time.Clock.tickToTock(0,False)
<syntaxhighlight lang="zkl">zkl: Time.Clock.tickToTock(0,False)
L(1970,1,1,0,0,0) // y,m,d, h,m,s</lang>
L(1970,1,1,0,0,0) // y,m,d, h,m,s</syntaxhighlight>




Line 1,064: Line 1,227:
{{omit from|Locomotive Basic}}
{{omit from|Locomotive Basic}}
{{omit from|ZX Spectrum Basic}}
{{omit from|ZX Spectrum Basic}}
{{omit from|6502 Assembly|Depends entirely on implementation}}
{{omit from|68000 Assembly|Depends entirely on implementation}}
{{omit from|8080 Assembly|Depends entirely on implementation}}
{{omit from|8086 Assembly|Depends entirely on implementation}}
{{omit from|ARM Assembly|Depends entirely on implementation}}
{{omit from|MIPS Assembly|Depends entirely on implementation}}
{{omit from|Z80 Assembly|Depends entirely on implementation}}

Latest revision as of 15:50, 5 February 2024

Task
Show the epoch
You are encouraged to solve this task according to the task description, using any language you may know.
Task

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/etc.,   or another way that will still show the epoch even if it is changed behind the scenes by the implementers),   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.


Related task



ABAP

DATA: lv_date TYPE datum.

lv_date = 0.

WRITE: / lv_date.
Output:
00.00.0000

Simplified

cl_demo_output=>display( |Result: { CONV datum( 0 ) }| ).
Output:
00.00.0000

Ada

In Ada, time is a private type and is implementation defined, for instance, on 64 bit GNAT, time is represented internally as nanoseconds relative to Jan 1, 2150.

However, conversion from unix epoch seconds is also supported and shown below.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Conversions; use Ada.Calendar.Conversions;
procedure ShowEpoch is
   etime : Time := To_Ada_Time (0);
begin
   Put_Line (Image (Date => etime));
end ShowEpoch;
Output:
1970-01-01 00:00:00

AppleScript

There are no fewer than three epochs associated with Mac OS. The original was 1st January 1904 00:00:00. This is stated in the 1999 AppleScript Language Guide, but I don't recall there ever having been a way to find it out by script and I don't think time zone was considered. Mac OS X was introduced in 2001 with a "Cocoa" framework whose epoch was the first instant (UTC) of that year and "underlying UNIX functionality". The do shell script added to AppleScript later that year made it possible for scripts to discover the Unix epoch. Since Mac OS X 10.9 (for library scripts) and Mac OS 10.10 (for running scripts), AppleScript's been able to access parts of the Cocoa system without needing add-ons and is thereby able to get the Cocoa epoch.

use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions

local CocoaEpoch, UnixEpoch

-- Get the date 0 seconds from the Cocoa epoch.
set CocoaEpoch to current application's class "NSDate"'s dateWithTimeIntervalSinceReferenceDate:(0)
-- The way it's rendered in its 'description' is good enough for the current purpose.
set CocoaEpoch to CocoaEpoch's |description|() as text

-- Get the date 0 seconds from the Unix epoch and format it in the same way.
set UnixEpoch to (do shell script "date -ur 0 '+%F %T %z'")

return "Cocoa epoch:  " & CocoaEpoch & linefeed & "Unix epoch:  " & UnixEpoch
Output:
"Cocoa epoch:  2001-01-01 00:00:00 +0000
Unix epoch:  1970-01-01 00:00:00 +0000"

Arturo

print to :date 0            ; convert UNIX timestamp: 0 to date

print now
print to :integer now       ; convert current date to UNIX timestamp
Output:
1970-01-01T01:00:00+01:00
2021-05-22T09:27:18+02:00
1621668438

AWK

# syntax: GAWK -f SHOW_THE_EPOCH.AWK
# requires GNU Awk 4.0.1 or later
BEGIN {
    print(strftime("%Y-%m-%d %H:%M:%S",0,1))
    exit(0)
}
Output:
1970-01-01 00:00:00

BBC BASIC

      INSTALL @lib$+"DATELIB"
      PRINT FN_date$(0, "dd-MMM-yyyy")

Output:

17-Nov-1858

C

#include <time.h>
#include <stdio.h>

int main() {
    time_t t = 0;
    printf("%s", asctime(gmtime(&t)));
    return 0;
}
Output:
Thu Jan  1 00:00:00 1970

Windows

FileTime, from the Win32 API, uses a different epoch.

Library: Win32
#include <windows.h>
#include <stdio.h>
#include <wchar.h>

int
main()
{
	FILETIME ft = {dwLowDateTime: 0, dwHighDateTime: 0};  /* Epoch */
	SYSTEMTIME st;
	wchar_t date[80], time[80];

	/*
	 * Convert FILETIME (which counts 100-nanosecond intervals since
	 * the epoch) to SYSTEMTIME (which has year, month, and so on).
	 *
	 * The time is in UTC, because we never call
	 * SystemTimeToTzSpecificLocalTime() to convert it to local time.
	 */
	FileTimeToSystemTime(&ft, &st);

	/*
	 * Format SYSTEMTIME as a string.
	 */
	if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL,
	    date, sizeof date / sizeof date[0]) == 0 ||
	    GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL,
	    time, sizeof time / sizeof time[0]) == 0) {
		fwprintf(stderr, L"Error!\n");
		return 1;
	}

	wprintf(L"FileTime epoch is %ls, at %ls (UTC).\n", date, time);
	return 0;
}
Output:
FileTime epoch is Monday, January 01, 1601, at 12:00:00 AM (UTC).

C#

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine(new DateTime());
    }
}
Output:
1-1-0001 0:00:00

C++

Works with: C++11
Works with: gcc version 4.5.3

Doesn't work with MSVC 10 SP1

#include <iostream>
#include <chrono>
#include <ctime>
int main()
{
    std::chrono::system_clock::time_point epoch;
    std::time_t t = std::chrono::system_clock::to_time_t(epoch);
    std::cout << std::asctime(std::gmtime(&t)) << '\n';
    return 0;
}
Output:
Thu Jan  1 00:00:00 1970
Library: boost
#include <iostream>
#include <boost/date_time.hpp>
int main()
{
    std::cout << boost::posix_time::ptime( boost::posix_time::min_date_time ) << '\n';
    return 0;
}
Output:
1400-Jan-01 00:00:00

Clojure

(println (java.util.Date. 0))

Output (since Clojure 1.5)

#inst "1970-01-01T00:00:00.000-00:00"

COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. epoch.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  epoch-date.
           03  year                PIC 9(4).
           03  month               PIC 99.
           03  dday                PIC 99.

       PROCEDURE DIVISION.
           MOVE FUNCTION DATE-OF-INTEGER(1) TO epoch-date

           DISPLAY year "-" month "-" dday

           GOBACK
           .
Output:
1601-01-01

CoffeeScript

console.log new Date(0).toISOString()
Output:
Thu, 01 Jan 1970 00:00:00 GMT

Common Lisp

(multiple-value-bind (second minute hour day month year) (decode-universal-time 0 0)
 	  (format t "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" year month day hour minute second))
Output:
1900-01-01 00:00:00

D

The Date struct of the standard library module "std.datetime" represents a date in the Proleptic Gregorian Calendar ranging from 32,768 B.C. to 32,767 A.D.

Dart

main() {
  print(new Date.fromEpoch(0,new TimeZone.utc()));
}
Output:
1970-01-01 00:00:00.000Z

Delphi

program ShowEpoch;

{$APPTYPE CONSOLE}

uses SysUtils;

begin
  Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.
Output:
1899-12-30 00:00:00.000

Erlang

Erlang uses 2 3-tuples for time and date manipulation. It is possible to get the current values from the operating system. It is also possible to transform these values to/from gregorian seconds. Those are seconds since the date and time interpreted with the Gregorian calendar extended back to year 0. Perhaps the epoch is the date and time at gregorian seconds 0?

2> calendar:universal_time().
{{2013,9,13},{8,3,16}}
3> calendar:datetime_to_gregorian_seconds(calendar:universal_time()).
63546278932
4> calendar:gregorian_seconds_to_datetime(63546278932).
{{2013,9,13},{8,8,52}}
11> calendar:gregorian_seconds_to_datetime(0).
{{0,1,1},{0,0,0}}

F#

printfn "%s" ((new System.DateTime()).ToString("u"))
Output:
0001-01-01 00:00:00Z

Factor

USING: calendar calendar.format io ;

0 micros>timestamp timestamp>ymdhms print
Output:
1970-01-01 00:00:00

Forth

Works with: 4tH version 3.61.3
include lib/longjday.4th
0 posix>jday .longjday  cr
Output:
Thursday, January 1, 1970

Fortran

Fortran offers no standard time-type variables nor library routines whereby a timestamp value is given as say some number of seconds from a particular epoch such as the start of the first of January 1970, etc. Individual systems and individual programmers have their own schemes, for instance counting the first of January 1900 as day one - whereby day zero is a Sunday. F90 introduced a complex subroutine with optional named parameters as well as an eight-element integer array whereby CALL DATE_AND_TIME(IVALS) when invoked returns the computer's current date and time as a four-digit year in IVAL(1), the month of the year in IVAL(2), the day of the month in IVAL(3), the difference in minutes with respect to UTC (ex-GMT) time in IVAL(4), and so on down to milliseconds in IVAL(8). One could then argue that the base epoch, day one for instance, is the first of January year 1 and discuss the proleptic Gregorian calendar.

FreeBASIC

FreeBASIC's built-in date/time library is based on an object called a 'date serial' which uses an epoch of 0:00 AM on December 30, 1899. This is the same epoch used internally for date/time purposes by COM, Visual Basic, Delphi, Excel, LibreOffice Calc and Google Sheets amongst others.

A DateSerial is a double precision floating point number whose integer part represents the number of days after (or in the case of a negative value, the number of days before) the epoch and the fractional part represents the time on that day. As such, the date/time range covered is virtually unlimited.

Date/time values in FB are always based on the current regional settings and so, if values are needed for other time-zones (or UTC), the appropriate adjustments must be made.

' FB 1.05.0 Win64

#Include "vbcompat.bi"

' The first argument to the Format function is a date serial
' and so the first statement below displays the epoch.

Dim f As String = "mmmm d, yyyy hh:mm:ss"
Print Format( 0 , f)      '' epoch
Print Format( 0.5, f)     '' noon on the same day
Print Format(-0.5, f)     '' noon on the previous day
Print Format(1000000, f)  '' one million days after the epoch
Print Format(-80000, f)   '' eighty thousand days before the epoch
Print
Print "Press any key to quit"
Sleep
Output:
December 30, 1899 00:00:00
December 30, 1899 12:00:00
December 29, 1899 12:00:00
November 26, 4637 00:00:00
December 17, 1680 00:00:00

Frink

Internally, Frink references all date/time values as a number of seconds relative to Julian Day 0 referenced to UTC. The internal numeric type is Frink's "do the right thing" numeric type which can be exact rational numbers, arbitrary-precision floating-point numbers, or even intervals, which gives essentially arbitrary precision and exact round-trip capability to any date/time value stored. These are transparently converted to arbitrary timezones or date systems for display.

println[ JD[0 s] -> UTC ]
Output:
BC 4713-01-01 PM 12:00:00.000 (Mon) Coordinated Universal Time

Frink also makes it easy to work with date/time values referenced to any arbitrary epoch. For example, to find the number of nanoseconds since the UNIX epoch:

epoch = # 1970 UTC #
now[] - epoch -> ns
Output:
1665439770353000000

Or to add a number of seconds to the UNIX epoch and find the result in Japan's timezone:

epoch = # 1970 UTC #
epoch + 2 billion seconds -> Japan
Output:
AD 2033-05-18 PM 12:33:20.000 (Wed) Japan Standard Time

Leap seconds are usually not taken into account in these calculations, but they can be easily using Frink's leap-second functions.

FutureBasic

window 1

print date$
print date$("d MMM yyyy")
print date$("EEE, MMM d, yyyy")
print date$("MMMM d, yyyy ")
print date$("MMMM d, yyyy G")
print "This is day ";date$("D");" of the year"
print
print time$
print time$("hh:mm:ss")
print time$("h:mm a")
print time$("h:mm a zzz")
print
print time$("h:mm a ZZZZ "); date$("MMMM d, yyyy G")

HandleEvents

Output:

09/03/16
3 Sep 2016
Sat, Sep 3, 2016
September 3, 2016 
September 3, 2016 AD
This is day 247 of the year

23:44:12
11:44:12
11:44 PM
11:44 PM EDT

11:44 PM GMT-04:00 September 3, 2016 AD

Go

package main
import ("fmt"; "time")

func main() {
    fmt.Println(time.Time{})
}
Output:

This is UNIX format. The 1 on the end is the full year, not two or four digit year.

Mon Jan  1 00:00:00 +0000 UTC 1

Groovy

Groovy uses the UNIX epoch.

def date = new Date(0)
def format = new java.text.SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ')
format.timeZone = TimeZone.getTimeZone('UTC')
println (format.format(date))
Output:
1970-01-01T00:00:00.000+0000

Haskell

Old time library

The ClockTime type is abstract in Haskell 98, but is defined in GHC.

Works with: GHC
import System.Time

main = putStrLn $ calendarTimeToString $ toUTCTime $ TOD 0 0
Output:
Thu Jan  1 00:00:00 UTC 1970

New time library

Works with: GHC
import Data.Time

main = print $ UTCTime (ModifiedJulianDay 0) 0
Output:
1858-11-17 00:00:00 UTC

Icon and Unicon

Date and Time can be accessed via a number of keywords and functions

  • The following are available in both Icon and Unicon
    • &clock, &date, &dateline, and &time deal with current times and dates
  • The following are specific to Unicon
    • &now provides the number of seconds since the epoch, Jan 1, 1970 00:00:00
    • ctime(integer) takes the number of seconds since the epoch and returns the date and time as a string in the local timezone
    • gtime(integer) takes the number of seconds since the epoch and returns the date and time as a string in UTC
    • gettimeofday() returns a record with the current time since the epoch in seconds and microseconds
  • datetime routines use a global variable 'DateBaseYear' which defaults to Jan 1, 1970 00:00:00 but can be set if desired.
  • The example below uses only a couple of the datetime procedures
link printf,datetime

procedure main()
  # Unicon
  now := gettimeofday().sec
  if now = &now then printf("&now and gettimeofday().sec are equal\n") 
  printf("Now (UTC) %s, (local) %s\n",gtime(now),ctime(now))
  printf("Epoch %s\n",gtime(0))
  # Icon and Unicon
  now := DateToSec(&date) + ClockToSec(&clock)
  printf("Now is also %s and %s\n",SecToDate(now),SecToDateLine(now))  
end
Sample Output:
&now and gettimeofday().sec are equal
Now (UTC) Tue Aug 09 10:43:23 2011, (local) Tue Aug 09 06:43:23 2011
Epoch Thu Jan 01 00:00:00 1970
Now is also 2011/08/09 and Tuesday, August 9, 2011  6:43 am

J

J does not have an epoch. J's native representation of date and time is a six element list: year, month, day, hour, minute, second. For example:

   6!:0''
2011 8 8 20 25 44.725

(August 8, 2011, 8:25:44 pm)

That said, the 'dates' library does have an epoch:

   require'dates'
   todate 0
1800 1 1

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 (as well as java.sql.Date, which can be subbed into this example) is actually in GMT, but there isn't a significant difference between that and UTC for lots of applications (documentation for java.util.Date).

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));
    }
}
Output:
Jan 1, 1970 12:00:00 AM

On my PC I see

01.01.1970 00:00:00

Using Java 8

Java 8 introduced the classes LocalDate, LocalTime, LoclDateTime,
and other associated classes which simplified the manipulation of dates and times.
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public final class ShowTheEpoch {

	public static void main(String[] args) {
		System.out.println(LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC));
	}

}
Output:
1970-01-01T00:00

JavaScript

document.write(new Date(0).toUTCString());
Output:
Thu, 01 Jan 1970 00:00:00 GMT

Joy

0 gmtime "%Y-%m-%d %H:%M:%S" strftime.
Output:
"1970-01-01 00:00:00"

jq

0 | todate
Output:
"1970-01-01T00:00:00Z"

Julia

Works with: Julia version 0.6
using Base.Dates  # just using Dates in versions > 0.6
println("Time zero (the epoch) is $(unix2datetime(0)).")
Output:
Time zero (the epoch) is 1970-01-01T00:00:00.

Kotlin

Translation of: Java
// version 1.1.2

import java.util.Date
import java.util.TimeZone
import java.text.DateFormat

fun main( args: Array<String>) {
    val epoch = Date(0)
    val format = DateFormat.getDateTimeInstance()
    format.timeZone = TimeZone.getTimeZone("UTC")
    println(format.format(epoch))
}
Output:
Jan 1, 1970 12:00:00 AM

Lasso

date(0.00)
date(0)
Output:
1969-12-31 19:00:00
1969-12-31 19:00:00

Limbo

implement Epoch;

include "sys.m"; sys: Sys;
include "draw.m";
include "daytime.m"; daytime: Daytime;
	Tm: import daytime;

Epoch: module {
	init: fn(nil: ref Draw->Context, nil: list of string);
};

init(nil: ref Draw->Context, nil: list of string)
{
	sys = load Sys Sys->PATH;
	daytime = load Daytime Daytime->PATH;
	sys->print("%s\n", daytime->text(daytime->gmt(0)));
}

Of course, this could also be done by mangling the namespace and forging the current date, locking it to the epoch:

implement Epoch;

include "sys.m"; sys: Sys;
include "draw.m";
include "daytime.m"; daytime: Daytime;
	Tm: import daytime;

Epoch: module {
	init: fn(nil: ref Draw->Context, nil: list of string);
};

init(nil: ref Draw->Context, nil: list of string)
{
	sys = load Sys Sys->PATH;
	daytime = load Daytime Daytime->PATH;

	# Create a file containing a zero:
	fd := sys->open("/tmp/0", Sys->OWRITE);
	if(fd == nil) {
		sys->fprint(sys->fildes(2), "Couldn't open /tmp/0 for writing: %r\n");
		raise "fail:errors";
	}
	sys->fprint(fd, "0");
	fd = nil; # Files with no references are closed immediately.

	# Fork the namespace so as not to disturb the parent
	# process's concept of time:
	sys->pctl(Sys->FORKNS, nil);
	# Bind that file over /dev/time:
	sys->bind("/tmp/0", "/dev/time", Sys->MREPL);
	
	# Print the "current" date, now the epoch:
	sys->print("%s\n", daytime->text(daytime->gmt(daytime->now())));
}
Output:
Thu Jan 01 00:00:00 GMT 1970

Lingo

Lingo's date object is not based on an epoch, but instead on runtime date calculations. A new date object is created by specifying "year, month, day", based on gregorian calendar. In arithmetic context, date objects are casted to "days" (AD), not to seconds or milliseconds (see below).

now = the systemDate
put now
-- date( 2018, 3, 21 )

babylonianDate = date(-1800,1,1)

-- print approx. year difference between "babylonianDate" and now
put (now-babylonianDate)/365.2425
-- 3818.1355

LiveCode

LiveCode uses midnight, January 1, 1970 as the start of the eon

put 0 into somedate
convert somedate to internet date
put somedate

-- output GMT (localised)
-- Thu, 1 Jan 1970 10:00:00 +1000

LotusScript

Uses LotusScript to calculate difference between current time and epoch start date. This example: a button which prints the result. Of course, change the timeStamp variable to whatever suits your need.

Sub Click(Source As Button)
  'Create timestamp as of now
  Dim timeStamp As NotesDateTime
  Set timeStamp = New NotesDateTime ( Now )

  'Assign epoch start time to variable
  Dim epochTime As NotesDateTime
  Set epochTime = New NotesDateTime ( "01/01/1970 00:00:00 AM GMT" )  ''' These two commands only to get epoch time.

  'Calculate time difference between both dates
  Dim epochSeconds As Long
  epochSeconds = timeStamp.TimeDifference ( epochTime )
  
  'Print result
  Print epochSeconds

End Sub

Output:

1445093823

Lua

print(os.date("%c", 0))
Output:
Thu Jan  1 00:00:00 1970

Mathematica/Wolfram Language

DateString[0]
Output:
Mon 1 Jan 1900 00:00:00

MATLAB / Octave

Matlab and Octave store date/time number in a floating point number counting the days.

d = [0,1,2,3.5,-3.5,1000*365,1000*366,now+[-1,0,1]];
for k=1:length(d)
    printf('day %f\t%s\n',d(k),datestr(d(k),0))
    disp(datevec(d(k)))
end;
Output:
day 0.000000	31-Dec--001 00:00:00
   -1   12   31    0    0    0
day 1.000000	01-Jan-0000 00:00:00
   0   1   1   0   0   0
day 2.000000	02-Jan-0000 00:00:00
   0   1   2   0   0   0
day 3.500000	03-Jan-0000 12:00:00
    0    1    3   12    0    0
day -3.500000	27-Dec--001 12:00:00
   -1   12   27   12    0    0
day 365000.000000	02-May-0999 00:00:00
   999     5     2     0     0     0
day 366000.000000	27-Jan-1002 00:00:00
   1002      1     27      0      0      0
day 734908.972013	09-Feb-2012 23:19:41
   2012.0000      2.0000      9.0000     23.0000     19.0000     41.9633
day 734909.972013	10-Feb-2012 23:19:41
   2012.0000      2.0000     10.0000     23.0000     19.0000     41.9633
day 734910.972013	11-Feb-2012 23:19:41
   2012.0000      2.0000     11.0000     23.0000     19.0000     41.9633

Which is to say, day one is the first of January, year zero - except that there is no year zero: one BC is followed by one AD (or, 1 BCE and 1 CE) and the Gregorian calendar scheme wasn't in use then either.

Maxima

timedate(0);
"1900-01-01 10:00:00+10:00"

min

0 datetime puts!
Output:
1970-01-01T00:00:00Z

NetRexx

Translation of: Java
/* NetRexx */
options replace format comments java crossref symbols nobinary

import java.text.DateFormat

edate = Date(0)
zulu  = DateFormat.getDateTimeInstance()
zulu.setTimeZone(TimeZone.getTimeZone('UTC'))
say zulu.format(edate)
return

Output:

Jan 1, 1970 12:00:00 AM

NewLISP

(date 0)
->"Thu Jan 01 01:00:00 1970"

Nim

Nim “times” module provides procedures to convert to and from timestamps. Using these procedures, it’s easy to find the epoch, even on another system:

import times

echo "Epoch for Posix systems:  ", fromUnix(0).utc
echo "Epoch for Windows system: ", fromWinTime(0).utc
Output:
Epoch for Posix systems:  1970-01-01T00:00:00Z
Epoch for Windows system: 1601-01-01T00:00:00Z

Objective-C

#import <Foundation/Foundation.h>

int main(int argc, const char *argv[]) {
  @autoreleasepool {

    NSDate *t = [NSDate dateWithTimeIntervalSinceReferenceDate:0];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];
    NSLog(@"%@", [dateFormatter stringFromDate:t]);

  }
  return 0;
}
Log:
2001-01-01 00:00:00 +0000

OCaml

open Unix

let months = [| "January"; "February"; "March"; "April"; "May"; "June";
      "July"; "August"; "September"; "October"; "November"; "December" |]

let () =
  let t = Unix.gmtime 0.0 in
  Printf.printf "%s %d, %d\n" months.(t.tm_mon) t.tm_mday (1900 + t.tm_year)
Execution:
$ ocaml unix.cma epoch.ml
January 1, 1970

Oforth

import: date

0 asDateUTC println
Output:
1970-01-01 00:00:00,000

PARI/GP

GP has no built-in date or time system.

system("date -ur 0")

PARI, as usual, has access to the same resources as C.

Pascal

This works with Free Pascal:

Program ShowEpoch;

uses
  SysUtils;
 
begin
  Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now));
  Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.
Output:
:> ./SelfDescribingNumber
2011-12-13 00:57:41.378
1899-12-30 00:00:00.000

Perl

print scalar gmtime 0, "\n";
Output:
Thu Jan  1 00:00:00 1970

Phix

The standard Phix file builtins/datetime.e does not use an epoch, but instead expects absolute values, eg Jan 1st 1970 is {1970,1,1,...}. I suppose the closest we can get is:

with javascript_semantics
constant d0 = {0,1,1,0,0,0,1,1}
include builtins\timedate.e
?format_timedate(d0,"YYYY-MM-DD")
?format_timedate(d0,"Dddd, Mmmm d, YYYY")
"0000-01-01"
"Sunday, January 1, 0000"

Note that zeroes in DT_MONTH/DT_DAY/DT_DOW/DT_DOY will give it jip.
It only says Sunday because I told it to, plus day_of_week() is meaningless/wrong pre 1752, and blatently broken on 1st Jan 0AD.

PHP

<?php
echo gmdate('r', 0), "\n";
?>
Output:
Thu, 01 Jan 1970 00:00:00 +0000

PicoLisp

The 'date' function in PicoLisp returns a day number, starting first of March of the year zero. Calculated according to the gregorian calendar (despite that that calendar wasn't used in 0 AD yet).

: (date 1)
-> (0 3 1)  # Year zero, March 1st

Pike

The usual localtime() method for simple time extraction is available, but the built in Calendar module is a more diverse tool.

object cal = Calendar.ISO->set_timezone("UTC");
write( cal.Second(0)->format_iso_short() );
Output:
19700101T00:00:00

PL/I

*process source attributes xref;
 epoch: Proc Options(main);
 /*********************************************************************
 * 20.08.2013 Walter Pachl  shows that PL/I uses 15 Oct 1582 as epoch
 * DAYS returns a FIXED BINARY(31,0) value which is the number of days
 * (in Lilian format) corresponding to the date d.
 *********************************************************************/
 Dcl d Char(17);
 Put Edit(datetime(),days(datetime()))
         (Skip,a,f(15));
 d='15821015000000000';
 Put Edit(d         ,days(d))
         (Skip,a,f(15));
 d='15821014000000000';
 Put Edit(d         ,days(d))
         (Skip,a,f(15));
 End;

Result:

20130820072642956         157365
15821015000000000              1
15821014000000000
IBM0512I  ONCODE=2112  X in SECS(X,Y) or DAYS(X,Y) was outside the
          supported range.
   At offset +00000283 in procedure with entry EPOCH

PowerShell

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

[datetime] 0
Output:
Monday, January 01, 0001 12:00:00 AM

Three Alternates

Get-Date always returns its Kind property as Local:

Get-Date -Year 1 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0 -Millisecond 0
Output:
Monday, January 01, 0001 12:00:00 AM

This approach returns its Kind property as Unspecified:

New-Object -TypeName System.DateTime
Output:
Monday, January 01, 0001 12:00:00 AM

Here you could describe the epoch date's Kind property as being Utc. Formatting the output as a list for demonstration:

New-Object -TypeName System.DateTime -ArgumentList 1, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc) | Format-List
Output:
Date        : 1/1/0001 12:00:00 AM
Day         : 1
DayOfWeek   : Monday
DayOfYear   : 1
Hour        : 0
Kind        : Utc
Millisecond : 0
Minute      : 0
Month       : 1
Second      : 0
Ticks       : 0
TimeOfDay   : 00:00:00
Year        : 1
DateTime    : Monday, January 01, 0001 12:00:00 AM

PureBasic

If OpenConsole()
  PrintN(FormatDate("Y = %yyyy  M = %mm  D = %dd, %hh:%ii:%ss", 0))
  
  Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
  CloseConsole()
EndIf
Output:
Y = 1970  M = 01  D = 01, 00:00:00

Python

>>> import time
>>> time.asctime(time.gmtime(0))
'Thu Jan  1 00:00:00 1970'
>>>

R

> epoch <- 0
> class(epoch) <- class(Sys.time())
> format(epoch, "%Y-%m-%d %H:%M:%S %Z")
[1] "1970-01-01 00:00:00 UTC"

Racket

#lang racket
(require racket/date)
(date->string (seconds->date 0 #f))

Output:

"Thursday, January 1st, 1970"

Raku

(formerly Perl 6)

say DateTime.new(0)
Output:
1970-01-01T00:00:00Z

REXX

The epoch for the REXX language BIF   (Built-In Function)   DATE   is:   January 1st, year 1.

/*REXX program displays the number of days since the epoch for the DATE function (BIF). */

say '     today is: '  date()                    /*today's is format:     mm MON YYYY   */

days=date('Basedate')                            /*only the first char of option is used*/
say right(days, 40)         " days since the REXX base date of January 1st, year 1"

say ' and today is: '  date(, days, "B")         /*it should still be today (µSec later)*/
                    /*   ↑                ┌───◄─── This BIF (Built-In Function) is only */
                    /*   └─────────◄──────┘        for  newer  versions of  REXX  that  */
                    /*                             support the  2nd and 3rd  arguments. */
out:
     today is:   3 Aug 2012
                                   734717 days since the REXX base date of January 1st, year 1
 and today is:   3 Aug 2012

Ring

load "guilib.ring"

New qApp {
         win1 = new qMainWindow() {
                setwindowtitle("Using QDateEdit")
                setGeometry(100,100,250,100)
                oDate = new qdateedit(win1) {
                        setGeometry(20,40,220,30) 
	                oDate.minimumDate()
                }
                show()
                }
                exec()
                }

Output:

RPL

RPL can not go back into the past beyond 15 October 1582.

15.101582 -1 DATE+
Output:
DATE+ Error:
Bad Argument Value

Ruby

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

The Date class however uses the Julian date -4712-1-1 as default when no parameters are supplied

require "date"
Date.new # => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)>

Run BASIC

eDate$ = date$("01/01/0001")
cDate$ = date$(0) ' 01/01/1901
sDate$ = date$("01/01/1970")

Rust

extern crate time;

use time::{at_utc, Timespec};

fn main() {
    let epoch = at_utc(Timespec::new(0, 0));  
    println!("{}", epoch.asctime());
}
Output:
Thu Jan  1 00:00:00 1970

Scala

import java.util.{Date, TimeZone, Locale}
import java.text.DateFormat

val df=DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.ENGLISH)
df.setTimeZone(TimeZone.getTimeZone("UTC"))
println(df.format(new Date(0)))
Output:
January 1, 1970 12:00:00 AM UTC

Scheme

Works with: Chez Scheme
; Display date at Time Zero in UTC.
(printf "~s~%" (time-utc->date (make-time 'time-utc 0 0) 0))
Output:
#<date Thu Jan  1 00:00:00 1970>

Seed7

The Seed7 library time.s7i defines the type time, which describes times and dates. For dates the proleptic Gregorian calendar is used (which assumes that the Gregorian calendar was even in effect at dates preceding its official introduction). This convention is used according to ISO 8601, which also defines that positive and negative years exist and that the year preceding 1 is 0. Therefore the epoch is the beginning of the year 0.

$ include "seed7_05.s7i";
  include "time.s7i";

const proc: main is func
  begin
    writeln(time.value);
  end func;
Output:
0000-01-01 00:00:00 UTC

Sidef

say Time.new(0).gmtime.ctime;
Output:
Thu Jan  1 00:00:00 1970

Standard ML

- Date.toString (Date.fromTimeUniv Time.zeroTime);
val it = "Thu Jan  1 00:00:00 1970" : string

Stata

. di %td 0
01jan1960
. di %tc 0
01jan1960 00:00:00

Tcl

% clock format 0 -gmt 1
Thu Jan 01 00:00:00 GMT 1970

TUSCRIPT

$$ MODE TUSCRIPT
- epoch
number=1
dayofweeknr=DATE (date,day,month,year,number)
epoch=JOIN(year,"-",month,day)
PRINT "epoch: ", epoch," (daynumber ",number,")"
- today's daynumber
dayofweeknr=DATE (today,day,month,year,number)
date=JOIN (year,"-",month,day)
PRINT "today's date: ", date," (daynumber ", number,")"
Output:
epoch: 1-1-1 (daynumber 1)
today's date: 2011-12-14 (daynumber 734487) 

uBasic/4tH

uBasic/4tH provides a TIME() function, which returns the common epoch, but doesn't provide a builtin function to display it - other than it's numerical value. This program shows the epoch in high level code.

Print Show(FUNC(_DateStr(0))), Show(FUNC(_TimeStr(0)))
End

_DateStr                               ' convert epoch to date string
  Param (1)
  Local (6)

  a@ = a@ / 86400                      ' just get the number of days since epoch
  b@ = 1970+(a@/365)                   ' ball parking year, will not be accurate!

  d@ = 0
  For c@ = 1972 To b@ - 1 Step 4
    If (((c@%4) = 0) * ((c@%100) # 0)) + ((c@%400) = 0) Then d@ = d@+1
  Next

  b@ = 1970+((a@ - d@)/365)            ' calculating accurate current year by (x - extra leap days)
  e@ = ((a@ - d@)%365)+1               ' if current year is leap, set indicator to 1
  f@ = (((b@%4) = 0) * ((b@%100) # 0)) + ((b@%400) = 0)

  g@ = 0                               ' calculating current month
  For c@ = 0 To 11 Until e@ < (g@+1)
    g@ = g@ + FUNC(_Monthdays (c@, f@))
  Next
                                       ' calculating current date
  g@ = g@ - FUNC(_Monthdays (c@-1, f@))
                                       ' Print a@, d@, e@, f@
Return (Join (Str(b@), FUNC(_Format (c@, Dup("-"))), FUNC(_Format (e@ - g@, Dup("-")))))

_TimeStr                               ' convert epoch to time string
  Param (1)
Return (Join(Str((a@%86400)/3600), FUNC(_Format ((a@%3600)/60, Dup(":"))), FUNC(_Format (a@%60, Dup(":")))))

_Format    Param (2) : Return (Join (Iif (a@<10, Join(b@, "0"), b@), Str (a@)))
_Monthdays Param (2) : Return (((a@ + (a@<7)) % 2) + 30 - ((2 - b@) * (a@=1)))
Output:
1970-01-01      0:00:00

0 OK, 0:58 

UNIX Shell

The nonstandard option date -r takes seconds from the epoch, and prints date and time. See date(1) manual.

Works with: OpenBSD
$ date -ur 0
Thu Jan  1 00:00:00 UTC 1970

On systems with GNU date, you can do

$ TZ=UTC  date --date "$(date +%s) seconds ago"
Thu Jan  1 00:00:00 UTC 1970

Visual Basic

Sub Main()
    Debug.Print Format(0, "dd mmm yyyy hh:mm")
End Sub
Output (in debug window):
30 Dec 1899 00:00

Wren

Library: Wren-date

The epoch (or zero date/time) for the above module is midnight on 1st January, 0001 UTC according to the Gregorian proleptic calendar, though it can also cater for the Unix epoch as well.

import "./date" for Date

Date.default = Date.isoFull
var dt = Date.fromNumber(0)
System.print(dt)

var dt2 = Date.unixEpoch
System.print(dt2)
Output:
0001-01-01T00:00:00.000+00:00
1970-01-01T00:00:00.000+00:00

zkl

Using the method tickToTock(time_t,useLocalTime) on Linux. tickToTock converts a time_t (seconds since the epoch) to "human" time. False means use UTC (vs local time, the default).

zkl: Time.Clock.tickToTock(0,False)
L(1970,1,1,0,0,0) // y,m,d, h,m,s