Show the epoch: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
(13 intermediate revisions by 11 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>
Line 25:
</pre>
===Simplified===
<langsyntaxhighlight ABAPlang="abap">cl_demo_output=>display( |Result: { CONV datum( 0 ) }| ).
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 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 44:
begin
Put_Line (Image (Date => etime));
end ShowEpoch;</langsyntaxhighlight>
{{out}}
<pre>1970-01-01 00:00:00</pre>
Line 52:
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.
 
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
Line 66:
set UnixEpoch to (do shell script "date -ur 0 '+%F %T %z'")
 
return "Cocoa epoch: " & CocoaEpoch & linefeed & "Unix epoch: " & UnixEpoch</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"Cocoa epoch: 2001-01-01 00:00:00 +0000
Unix epoch: 1970-01-01 00:00:00 +0000"</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">print to :date 0 ; convert UNIX timestamp: 0 to date
 
print now
print to :integer now ; convert current date to UNIX timestamp</langsyntaxhighlight>
 
{{out}}
Line 86:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SHOW_THE_EPOCH.AWK
# requires GNU Awk 4.0.1 or later
Line 93:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 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 109:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <time.h>
#include <stdio.h>
 
Line 116:
printf("%s", asctime(gmtime(&t)));
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
Line 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 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 168:
Console.WriteLine(new DateTime());
}
}</langsyntaxhighlight>
{{out}}
<pre>1-1-0001 0:00:00</pre>
Line 176:
{{works with|gcc|4.5.3}}
Doesn't work with MSVC 10 SP1
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <chrono>
#include <ctime>
Line 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 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 221:
 
GOBACK
.</langsyntaxhighlight>
 
{{out}}
Line 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 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 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 275:
 
=={{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}}==
<langsyntaxhighlight lang="factor">USING: calendar calendar.format io ;
 
0 micros>timestamp timestamp>ymdhms print</langsyntaxhighlight>
{{out}}
<pre>
Line 290:
=={{header|Forth}}==
{{works with|4tH|3.61.3}}
<langsyntaxhighlight lang="forth">include lib/longjday.4th
0 posix>jday .longjday cr</langsyntaxhighlight>
{{out}}
<pre>
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.
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
#Include "vbcompat.bi"
Line 321:
Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 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 349 ⟶ 374:
print
print time$("h:mm a ZZZZ "); date$("MMMM d, yyyy G")
 
</lang>
HandleEvents</syntaxhighlight>
Output:
<pre>
Line 368 ⟶ 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 382 ⟶ 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 393 ⟶ 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 418 ⟶ 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 429 ⟶ 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 438 ⟶ 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 460 ⟶ 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}}
 
<langsyntaxhighlight lang="julia">using Base.Dates # just using Dates in versions > 0.6
println("Time zero (the epoch) is $(unix2datetime(0)).")</langsyntaxhighlight>
 
{{out}}
Line 487 ⟶ 539:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.util.Date
Line 498 ⟶ 550:
format.timeZone = TimeZone.getTimeZone("UTC")
println(format.format(epoch))
}</langsyntaxhighlight>
 
{{out}}
Line 506 ⟶ 558:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">date(0.00)
date(0)</langsyntaxhighlight>
 
{{out}}
Line 514 ⟶ 566:
 
=={{header|Limbo}}==
<langsyntaxhighlight Limbolang="limbo">implement Epoch;
 
include "sys.m"; sys: Sys;
Line 530 ⟶ 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 568 ⟶ 620:
sys->print("%s\n", daytime->text(daytime->gmt(daytime->now())));
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 578 ⟶ 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).
 
<langsyntaxhighlight Lingolang="lingo">now = the systemDate
put now
-- date( 2018, 3, 21 )
Line 586 ⟶ 638:
-- print approx. year difference between "babylonianDate" and now
put (now-babylonianDate)/365.2425
-- 3818.1355</langsyntaxhighlight>
 
=={{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 596 ⟶ 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 619 ⟶ 671:
 
End Sub
</syntaxhighlight>
</lang>
 
Output:
Line 627 ⟶ 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 668 ⟶ 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!</langsyntaxhighlight>
{{out}}
<pre>
Line 680 ⟶ 733:
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 690 ⟶ 743:
say zulu.format(edate)
return
</syntaxhighlight>
</lang>
'''Output:'''
<pre>
Line 697 ⟶ 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:
<langsyntaxhighlight lang="nim">import times
 
echo "Epoch for Posix systems: ", fromUnix(0).utc
echo "Epoch for Windows system: ", fromWinTime(0).utc</langsyntaxhighlight>
 
{{out}}
Line 712 ⟶ 765:
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main(int argc, const char *argv[]) {
Line 725 ⟶ 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 737 ⟶ 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 744 ⟶ 797:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: date
 
0 asDateUTC println</langsyntaxhighlight>
 
{{out}}
Line 755 ⟶ 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 761 ⟶ 814:
=={{header|Pascal}}==
This works with [[Free_Pascal| Free Pascal]]:
<langsyntaxhighlight lang="pascal">Program ShowEpoch;
 
uses
Line 769 ⟶ 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 778 ⟶ 831:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">print scalar gmtime 0, "\n";</langsyntaxhighlight>
{{out}}
<pre>Thu Jan 1 00:00:00 1970</pre>
Line 784 ⟶ 837:
=={{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:
<!--<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>
"0000-01-01"
Line 796 ⟶ 852:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
echo gmdate('r', 0), "\n";
?></langsyntaxhighlight>
{{out}}
<pre>Thu, 01 Jan 1970 00:00:00 +0000</pre>
Line 804 ⟶ 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">
<lang Pike>
object cal = Calendar.ISO->set_timezone("UTC");
write( cal.Second(0)->format_iso_short() );
</syntaxhighlight>
</lang>
{{Out}}
<pre>19700101T00:00:00</pre>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">*process source attributes xref;
epoch: Proc Options(main);
/*********************************************************************
Line 833 ⟶ 889:
Put Edit(d ,days(d))
(Skip,a,f(15));
End;</langsyntaxhighlight>
Result:
<pre>
Line 846 ⟶ 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>
Line 852 ⟶ 908:
===Three Alternates===
<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
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 860 ⟶ 916:
</pre>
This approach returns its '''Kind''' property as Unspecified:
<syntaxhighlight lang="powershell">
<lang PowerShell>
New-Object -TypeName System.DateTime
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 869 ⟶ 925:
Here you could describe the epoch date's '''Kind''' property as being Utc.
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
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 891 ⟶ 947:
 
=={{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:
Line 926 ⟶ 982:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>say DateTime.new(0)</langsyntaxhighlight>
{{out}}
<pre>
Line 934 ⟶ 990:
=={{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.
<langsyntaxhighlight 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 */
Line 944 ⟶ 1,000:
/* ↑ ┌───◄─── This BIF (Built-In Function) is only */
/* └─────────◄──────┘ for newer versions of REXX that */
/* support the 2nd and 3rd arguments. */</langsyntaxhighlight>
{{output|out}}
<pre>
Line 953 ⟶ 1,009:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "guilib.ring"
 
Line 968 ⟶ 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
<langsyntaxhighlight lang="ruby">require "date"
Date.new # => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)>
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">eDate$ = date$("01/01/0001")
cDate$ = date$(0) ' 01/01/1901
sDate$ = date$("01/01/1970")</langsyntaxhighlight>
 
=={{header|Rust}}==
 
<langsyntaxhighlight lang="rust">extern crate time;
 
use time::{at_utc, Timespec};
Line 994 ⟶ 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|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 1,016 ⟶ 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 1,022 ⟶ 1,095:
begin
writeln(time.value);
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,029 ⟶ 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}}==
<langsyntaxhighlight lang="stata">. di %td 0
01jan1960
. di %tc 0
01jan1960 00:00:00</langsyntaxhighlight>
 
=={{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 1,057 ⟶ 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 1,064 ⟶ 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
Line 1,086 ⟶ 1,201:
{{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.
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
 
Date.default = Date.isoFull
Line 1,093 ⟶ 1,208:
 
var dt2 = Date.unixEpoch
System.print(dt2)</langsyntaxhighlight>
 
{{out}}
Line 1,103 ⟶ 1,218:
=={{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 1,112 ⟶ 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,482

edits