Show the epoch: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(40 intermediate revisions by 26 users not shown)
Line 14:
 
=={{header|ABAP}}==
<langsyntaxhighlight ABAPlang="abap">DATA: lv_date TYPE datum.
 
lv_date = 0.
 
WRITE: / lv_date.
</syntaxhighlight>
</lang>
{{out}}
<pre>
00.00.0000
</pre>
===Simplified===
<syntaxhighlight lang="abap">cl_demo_output=>display( |Result: { CONV datum( 0 ) }| ).
</syntaxhighlight>
{{out}}
<pre>
Line 29 ⟶ 36:
 
However, conversion from unix epoch seconds is also supported and shown below.
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
Line 37 ⟶ 44:
begin
Put_Line (Image (Date => etime));
end ShowEpoch;</langsyntaxhighlight>
{{out}}
<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}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SHOW_THE_EPOCH.AWK
# requires GNU Awk 4.0.1 or later
Line 49 ⟶ 93:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 57 ⟶ 101:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"DATELIB"
PRINT FN_date$(0, "dd-MMM-yyyy")</langsyntaxhighlight>
'''Output:'''
<pre>
Line 65 ⟶ 109:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <time.h>
#include <stdio.h>
 
Line 72 ⟶ 116:
printf("%s", asctime(gmtime(&t)));
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
Line 78 ⟶ 122:
FileTime, from the Win32 API, uses a different epoch.
{{libheader|Win32}}
<langsyntaxhighlight lang="c">#include <windows.h>
#include <stdio.h>
#include <wchar.h>
Line 111 ⟶ 155:
wprintf(L"FileTime epoch is %ls, at %ls (UTC).\n", date, time);
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>FileTime epoch is Monday, January 01, 1601, at 12:00:00 AM (UTC).</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 124 ⟶ 168:
Console.WriteLine(new DateTime());
}
}</langsyntaxhighlight>
{{out}}
<pre>1-1-0001 0:00:00</pre>
Line 132 ⟶ 176:
{{works with|gcc|4.5.3}}
Doesn't work with MSVC 10 SP1
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <chrono>
#include <ctime>
Line 141 ⟶ 185:
std::cout << std::asctime(std::gmtime(&t)) << '\n';
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
{{libheader|boost}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <boost/date_time.hpp>
int main()
Line 151 ⟶ 195:
std::cout << boost::posix_time::ptime( boost::posix_time::min_date_time ) << '\n';
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>1400-Jan-01 00:00:00</pre>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(println (java.util.Date. 0))</langsyntaxhighlight>
Output (since Clojure 1.5)
<syntaxhighlight lang="text">#inst "1970-01-01T00:00:00.000-00:00"</langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. epoch.
 
Line 177 ⟶ 221:
 
GOBACK
.</langsyntaxhighlight>
 
{{out}}
Line 183 ⟶ 227:
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">console.log new Date(0).toISOString()</langsyntaxhighlight>
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 GMT</pre>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight 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))</langsyntaxhighlight>
{{out}}
<pre>1900-01-01 00:00:00</pre>
Line 196 ⟶ 241:
 
=={{header|Dart}}==
<langsyntaxhighlight lang="dart">main() {
print(new Date.fromEpoch(0,new TimeZone.utc()));
}</langsyntaxhighlight>
{{out}}
<pre>1970-01-01 00:00:00.000Z</pre>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program ShowEpoch;
 
{$APPTYPE CONSOLE}
Line 211 ⟶ 256:
begin
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.</langsyntaxhighlight>
{{out}}
<pre>1899-12-30 00:00:00.000</pre>
Line 228 ⟶ 273:
{{0,1,1},{0,0,0}}
</pre>
 
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">printfn "%s" ((new System.DateTime()).ToString("u"))</langsyntaxhighlight>
{{out}}
<pre>0001-01-01 00:00:00Z</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: calendar calendar.format io ;
<lang factor>
 
IN: USE: calendar calendar.format
IN: 0 micros>timestamp timestamp>ymdhms .print</syntaxhighlight>
{{out}}
"1970-01-01 00:00:00"
</langpre>
1970-01-01 00:00:00
</pre>
 
=={{header|Forth}}==
{{works with|4tH|3.61.3}}
<langsyntaxhighlight lang="forth">include lib/longjday.4th
0 posix>jday .longjday cr</langsyntaxhighlight>
{{out}}
<pre>
Line 260 ⟶ 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.
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
#Include "vbcompat.bi"
Line 275 ⟶ 321:
Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 285 ⟶ 331:
December 17, 1680 00:00:00
</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}}==
<langsyntaxhighlight lang="futurebasic">window 1
include "ConsoleWindow"
 
print date$
Line 303 ⟶ 374:
print
print time$("h:mm a ZZZZ "); date$("MMMM d, yyyy G")
 
</lang>
HandleEvents</syntaxhighlight>
Output:
<pre>
Line 322 ⟶ 394:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
import ("fmt"; "time")
 
func main() {
fmt.Println(time.Time{})
}</langsyntaxhighlight>
{{out}}
This is UNIX format. The 1 on the end is the full year, not two or four digit year.
Line 336 ⟶ 408:
=={{header|Groovy}}==
Groovy uses the UNIX epoch.
<langsyntaxhighlight lang="groovy">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))</langsyntaxhighlight>
{{out}}
<pre>1970-01-01T00:00:00.000+0000</pre>
Line 347 ⟶ 419:
The <code>ClockTime</code> type is abstract in Haskell 98, but is defined in GHC.
{{works with|GHC}}
<langsyntaxhighlight lang="haskell">import System.Time
 
main = putStrLn $ calendarTimeToString $ toUTCTime $ TOD 0 0</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 UTC 1970</pre>
===New time library===
{{works with|GHC}}
<langsyntaxhighlight lang="haskell">import Data.Time
 
main = print $ UTCTime (ModifiedJulianDay 0) 0</langsyntaxhighlight>
{{out}}
<pre>1858-11-17 00:00:00 UTC</pre>
Line 372 ⟶ 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.
* The example below uses only a couple of the datetime procedures
<langsyntaxhighlight Uniconlang="unicon">link printf,datetime
 
procedure main()
Line 383 ⟶ 455:
now := DateToSec(&date) + ClockToSec(&clock)
printf("Now is also %s and %s\n",SecToDate(now),SecToDateLine(now))
end</langsyntaxhighlight>
{{out|Sample Output}}
<pre>&now and gettimeofday().sec are equal
Line 392 ⟶ 464:
=={{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:
<langsyntaxhighlight lang="j"> 6!:0''
2011 8 8 20 25 44.725</langsyntaxhighlight>
(August 8, 2011, 8:25:44 pm)
 
That said, the <code>'dates'</code> library does have an epoch:
<langsyntaxhighlight lang="j"> require'dates'
todate 0
1800 1 1</langsyntaxhighlight>
 
=={{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]).
<langsyntaxhighlight lang="java">import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
Line 414 ⟶ 486:
System.out.println(format.format(date));
}
}</langsyntaxhighlight>
{{out}}
<pre>Jan 1, 1970 12:00:00 AM</pre>
On my PC I see
<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}}==
<langsyntaxhighlight lang="javascript">document.write(new Date(0).toUTCString());</langsyntaxhighlight>
{{out}}
<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}}==
<syntaxhighlight lang ="jq">0 | todate</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">"1970-01-01T00:00:00Z"</langsyntaxhighlight>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang>
 
println("Time zero (the epoch) is ", strftime("%c", 0), ".")
<syntaxhighlight lang="julia">using Base.Dates # just using Dates in versions > 0.6
</lang>
println("Time zero (the epoch) is $(unix2datetime(0)).")</syntaxhighlight>
 
{{out}}
<pre>Time zero (the epoch) is 1970-01-01T00:00:00.</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="scala">// 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))
}</syntaxhighlight>
 
{{out}}
<pre>
Jan 1, 1970 12:00:00 AM
Time zero (the epoch) is Wed 31 Dec 1969 06:00:00 PM CST.
</pre>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">date(0.00)
date(0)</langsyntaxhighlight>
 
{{out}}
Line 449 ⟶ 566:
 
=={{header|Limbo}}==
<langsyntaxhighlight Limbolang="limbo">implement Epoch;
 
include "sys.m"; sys: Sys;
Line 465 ⟶ 582:
daytime = load Daytime Daytime->PATH;
sys->print("%s\n", daytime->text(daytime->gmt(0)));
}</langsyntaxhighlight>
 
Of course, this could also be done by mangling the namespace and forging the current date, locking it to the epoch:
 
<langsyntaxhighlight Limbolang="limbo">implement Epoch;
 
include "sys.m"; sys: Sys;
Line 503 ⟶ 620:
sys->print("%s\n", daytime->text(daytime->gmt(daytime->now())));
}
</syntaxhighlight>
</lang>
 
{{out}}
<pre>Thu Jan 01 00:00:00 GMT 1970
</pre>
 
=={{header|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).
 
<syntaxhighlight lang="lingo">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</syntaxhighlight>
 
=={{header|LiveCode}}==
LiveCode uses midnight, January 1, 1970 as the start of the eon
<langsyntaxhighlight LiveCodelang="livecode">put 0 into somedate
convert somedate to internet date
put somedate
Line 517 ⟶ 648:
-- output GMT (localised)
-- Thu, 1 Jan 1970 10:00:00 +1000
</syntaxhighlight>
</lang>
 
=={{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.
 
<langsyntaxhighlight lang="lotusscript">
Sub Click(Source As Button)
'Create timestamp as of now
Line 540 ⟶ 671:
 
End Sub
</syntaxhighlight>
</lang>
 
Output:
Line 548 ⟶ 679:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">print(os.date("%c", 0))</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang Mathematica="mathematica">DateString[0]</langsyntaxhighlight>
{{out}}
->Mon 1 Jan 1900 00:00:00
<pre>Mon 1 Jan 1900 00:00:00</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
Matlab and Octave store date/time number in a floating point number counting the days.
<langsyntaxhighlight lang="matlab">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;</langsyntaxhighlight>
{{out}}
<pre>day 0.000000 31-Dec--001 00:00:00
Line 589 ⟶ 721:
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">timedate(0);
"1900-01-01 10:00:00+10:00"</langsyntaxhighlight>
 
=={{header|min}}==
<syntaxhighlight lang="min">0 datetime puts!</syntaxhighlight>
{{out}}
<pre>
1970-01-01T00:00:00Z
</pre>
 
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 604 ⟶ 743:
say zulu.format(edate)
return
</syntaxhighlight>
</lang>
'''Output:'''
<pre>
Line 611 ⟶ 750:
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(date 0)
->"Thu Jan 01 01:00:00 1970"</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main(int argc, const char *argv[]) {
Line 635 ⟶ 778:
}
return 0;
}</langsyntaxhighlight>
{{out|Log}}
<pre>2001-01-01 00:00:00 +0000</pre>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">open Unix
 
let months = [| "January"; "February"; "March"; "April"; "May"; "June";
Line 647 ⟶ 790:
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)</langsyntaxhighlight>
{{out|Execution}}
<pre>$ ocaml unix.cma epoch.ml
Line 654 ⟶ 797:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: date
 
0 asDateUTC println</langsyntaxhighlight>
 
{{out}}
Line 665 ⟶ 808:
=={{header|PARI/GP}}==
GP has no built-in date or time system.
<langsyntaxhighlight lang="parigp">system("date -ur 0")</langsyntaxhighlight>
 
PARI, as usual, has access to the same resources as [[#C|C]].
Line 671 ⟶ 814:
=={{header|Pascal}}==
This works with [[Free_Pascal| Free Pascal]]:
<langsyntaxhighlight lang="pascal">Program ShowEpoch;
 
uses
Line 679 ⟶ 822:
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now));
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 688 ⟶ 831:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">print scalar gmtime 0, "\n";</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
 
=={{header|Perl 6Phix}}==
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:
<lang perl6>say DateTime.new(0)</lang>
<!--<syntaxhighlight lang="phix">(phixonline)-->
{{out}}
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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>
<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>
<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>
"0000-01-01"
1970-01-01T00:00:00Z
"Sunday, January 1, 0000"
</pre>
Note that zeroes in DT_MONTH/DT_DAY/DT_DOW/DT_DOY will give it jip.<br>
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.
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
echo gmdate('r', 0), "\n";
?></langsyntaxhighlight>
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 +0000</pre>
Line 708 ⟶ 860:
=={{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).
<langsyntaxhighlight PicoLisplang="picolisp">: (date 1)
-> (0 3 1) # Year zero, March 1st</langsyntaxhighlight>
 
=={{header|Pike}}==
The usual localtime() method for simple time extraction is available, but the built in Calendar module is a more diverse tool.
<syntaxhighlight lang="pike">
object cal = Calendar.ISO->set_timezone("UTC");
write( cal.Second(0)->format_iso_short() );
</syntaxhighlight>
{{Out}}
<pre>19700101T00:00:00</pre>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">*process source attributes xref;
epoch: Proc Options(main);
/*********************************************************************
Line 728 ⟶ 889:
Put Edit(d ,days(d))
(Skip,a,f(15));
End;</langsyntaxhighlight>
Result:
<pre>
Line 741 ⟶ 902:
=={{header|PowerShell}}==
PowerShell uses .NET's <code>DateTime</code> structure and an integer can simply be casted appropriately:
<syntaxhighlight lang ="powershell">[datetime] 0</langsyntaxhighlight>
{{out}}
<pre>Monday, January 01, 0001 12:00:00 AM</pre>
 
===Three Alternates===
<code>Get-Date</code> always returns its '''Kind''' property as Local:
<syntaxhighlight lang="powershell">
Get-Date -Year 1 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0 -Millisecond 0
</syntaxhighlight>
{{Out}}
<pre>
Monday, January 01, 0001 12:00:00 AM
</pre>
This approach returns its '''Kind''' property as Unspecified:
<syntaxhighlight lang="powershell">
New-Object -TypeName System.DateTime
</syntaxhighlight>
{{Out}}
<pre>
Monday, January 01, 0001 12:00:00 AM
</pre>
Here you could describe the epoch date's '''Kind''' property as being Utc.
Formatting the output as a list for demonstration:
<syntaxhighlight lang="powershell">
New-Object -TypeName System.DateTime -ArgumentList 1, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc) | Format-List
</syntaxhighlight>
{{Out}}
<pre>
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
</pre>
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang="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</langsyntaxhighlight>
{{out}}
<pre>Y = 1970 M = 01 D = 01, 00:00:00</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">>>> import time
>>> time.asctime(time.gmtime(0))
'Thu Jan 1 00:00:00 1970'
>>></langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="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"</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(require racket/date)
(date->string (seconds->date 0 #f))
</syntaxhighlight>
</lang>
 
Output:
<pre>
"Thursday, January 1st, 1970"
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>say DateTime.new(0)</syntaxhighlight>
{{out}}
<pre>
1970-01-01T00:00:00Z
</pre>
 
=={{header|REXX}}==
The epoch for the REXX language builtBIF &nbsp; (<u>B</u>uilt-in<u>I</u>n function<u>F</u>unction) &nbsp; '''DATE''' &nbsp; is: &nbsp; January 1st, year 1.
<langsyntaxhighlight lang="rexx">/*REXX program showsdisplays 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 1stthe first char of option is used*/
say right(days,35 40) " days since the REXX base date of January 1st, year 1"
 
say ' and today is: ' date(, days,' "B'") /*thisit should still be today (stillµSec later). */
/* ↑ ┌───◄─── This BIF (Built-In Function) is only */
 
/* └─────────◄──────┘ for newer versions of REXX that */
/*──────── The above statement is only valid for the newer REXXes,*/
/*──────── older versions don't support the 2nd and 3rd arguments. */</langsyntaxhighlight>
'''{{output'''|out}}
<pre>
<pre style="overflow:scroll">
today is: 3 Aug 2012
734717 days since the REXX base date of January 1st, year 1
and today is: 3 Aug 2012
</pre>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "guilib.ring"
 
Line 815 ⟶ 1,024:
exec()
}
</syntaxhighlight>
</lang>
Output:
[[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}}==
<langsyntaxhighlight lang="ruby">irb(main):001:0> Time.at(0).utc
=> 1970-01-01 00:00:00 UTC</langsyntaxhighlight>
The Date class however uses the Julian date -4712-1-1 as default when no parameters are supplied
<syntaxhighlight lang="ruby">require "date"
Date.new # => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)>
</syntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">eDate$ = date$("01/01/0001")
cDate$ = date$(0) ' 01/01/1901
sDate$ = date$("01/01/1970")</syntaxhighlight>
 
=={{header|Rust}}==
 
<langsyntaxhighlight lang="rust">extern crate time;
 
use time::{at_utc, Timespec};
Line 832 ⟶ 1,059:
let epoch = at_utc(Timespec::new(0, 0));
println!("{}", epoch.asctime());
}</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
 
=={{header|Run BASIC}}==
<lang runbasic>eDate$ = date$("01/01/0001")
cDate$ = date$(0) ' 01/01/1901
sDate$ = date$("01/01/1970")</lang>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="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)))</langsyntaxhighlight>
{{out}}
<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}}==
Line 859 ⟶ 1,089:
negative years exist and that the year preceding 1 is 0.
Therefore the epoch is the beginning of the year 0.
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
 
Line 865 ⟶ 1,095:
begin
writeln(time.value);
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 872 ⟶ 1,102:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">say Time.new(0).gmtime.ctime;</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">- Date.toString (Date.fromTimeUniv Time.zeroTime);
val it = "Thu Jan 1 00:00:00 1970" : string</langsyntaxhighlight>
 
=={{header|Stata}}==
<syntaxhighlight lang="stata">. di %td 0
01jan1960
. di %tc 0
01jan1960 00:00:00</syntaxhighlight>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">% clock format 0 -gmt 1
Thu Jan 01 00:00:00 GMT 1970</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
- epoch
number=1
Line 894 ⟶ 1,130:
dayofweeknr=DATE (today,day,month,year,number)
date=JOIN (year,"-",month,day)
PRINT "today's date: ", date," (daynumber ", number,")"</langsyntaxhighlight>
{{out}}
<pre>
Line 901 ⟶ 1,137:
</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}}==
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}}
<langsyntaxhighlight lang="bash">$ date -ur 0
Thu Jan 1 00:00:00 UTC 1970</langsyntaxhighlight>
 
On systems with GNU date, you can do
<langsyntaxhighlight lang="bash">
$ TZ=UTC date --date "$(date +%s) seconds ago"
Thu Jan 1 00:00:00 UTC 1970
</syntaxhighlight>
</lang>
 
=={{header|Visual Basic}}==
<langsyntaxhighlight lang="vb">Sub Main()
Debug.Print Format(0, "dd mmm yyyy hh:mm")
End Sub</langsyntaxhighlight>
{{out|Output (in debug window)}}
30 Dec 1899 00:00
 
=={{header|Wren}}==
{{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.
<syntaxhighlight lang="wren">import "./date" for Date
 
Date.default = Date.isoFull
var dt = Date.fromNumber(0)
System.print(dt)
 
var dt2 = Date.unixEpoch
System.print(dt2)</syntaxhighlight>
 
{{out}}
<pre>
0001-01-01T00:00:00.000+00:00
1970-01-01T00:00:00.000+00:00
</pre>
 
=={{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).
<langsyntaxhighlight lang="zkl">zkl: Time.Clock.tickToTock(0,False)
L(1970,1,1,0,0,0) // y,m,d, h,m,s</langsyntaxhighlight>
 
 
Line 931 ⟶ 1,227:
{{omit from|Locomotive 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}}
9,476

edits