System time: Difference between revisions

Add Ecstasy example
(System time en Asymptote)
(Add Ecstasy example)
 
(16 intermediate revisions by 14 users not shown)
Line 20:
<br><br>
=={{header|11l}}==
<syntaxhighlight lang ="11l">print(Time())</langsyntaxhighlight>
 
{{out}}
Line 29:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program sysTime64.s */
Line 235:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 242:
 
=={{header|ABAP}}==
<langsyntaxhighlight lang="aime">REPORT system_time.
 
WRITE: sy-uzeit.</langsyntaxhighlight>
 
=={{header|Ada}}==
The following example displays a date-time stamp. The time zone value is the number of minutes offset from the prime meridian.<langsyntaxhighlight lang="ada">with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones;
Line 256:
begin
Put_line(Image(Date => Now, Time_Zone => -7*60));
end System_Time;</langsyntaxhighlight>{{out}}
2008-01-23 19:14:19
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">date d;
 
d_now(d);
 
o_form("~-/f2/-/f2/ /f2/:/f2/:/f2/\n", d_year(d), d_y_month(d), d_m_day(d),
d_d_hour(d), d_h_minute(d), d_m_second(d));</langsyntaxhighlight>{{out}}
2011-09-04 15:05:08
 
Line 271:
<!-- {{does not work with|ALGOL 68|Standard - POSIX local time, and utc time extensions to language used}} -->
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - test missing transput, and POSIX local time, and utc time extensions to language used}} --><langsyntaxhighlight lang="algol68">FORMAT time repr = $"year="4d,", month="2d,", day="2d,", hours="2d,", \
minutes="2d,", seconds="2d,", day of week="d,", \
daylight-saving-time flag="dl$;
printf((time repr, local time));
printf((time repr, utc time))</langsyntaxhighlight>{{out}}
year=2009, month=03, day=12, hours=11, minutes=53, seconds=32, day of week=5, daylight-saving-time flag=0
year=2009, month=03, day=12, hours=01, minutes=53, seconds=32, day of week=5, daylight-saving-time flag=0
Line 281:
=={{header|AmigaBASIC}}==
 
<syntaxhighlight lang ="amigabasic">print date$,time$</langsyntaxhighlight>
{{output}}
<pre>11-19-2020 20:47:44</pre>
 
=={{header|AppleScript}}==
<langsyntaxhighlight AppleScriptlang="applescript">display dialog ((current date) as text)</langsyntaxhighlight>
{{out}}
<pre>
Line 294:
macOS's system time epoch is 1st January 2001 00:00:00 UTC. The number of seconds since then can be calculated in vanilla AppleScript like this:
 
<langsyntaxhighlight lang="applescript">set now to (current date)
set GMTOffset to (time to GMT)
copy now to epoch
Line 307:
set offsetStr to " +" & text 2 thru -1 of ((10000 + offsetStr) as text)
end if
return (now as text) & offsetStr & (linefeed & systemTime) & (" seconds since " & epoch & " UTC")</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"Tuesday 30 June 2020 at 11:34:31 +0100
6.15206071E+8 seconds since Monday 1 January 2001 at 00:00:00 UTC"</langsyntaxhighlight>
 
With AppleScriptObjC, it's more direct and fractions of a second are included:
 
<langsyntaxhighlight lang="applescript">use AppleScript version "2.4" -- Mac OS 10.10 (Yosemite) or later.
use framework "Foundation"
 
Line 330:
-- set epoch to current application's class "NSDate"'s dateWithTimeIntervalSinceReferenceDate:(0)
set epochAsText to epoch's |description|() as text
return nowAsText & (linefeed & systemTime) & (" seconds since " & epochAsText)</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"Tuesday 30 June 2020 at 11:34:34 British Summer Time
6.152060746444E+8 seconds since 2001-01-01 00:00:00 +0000"</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program sysTime.s */
Line 555:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 562:
=={{header|Arturo}}==
 
<syntaxhighlight lang ="rebol">print now</langsyntaxhighlight>
 
{{out}}
Line 570:
 
=={{header|Asymptote}}==
<langsyntaxhighlight Asymptotelang="asymptote">time();
time("%a %b %d %H:%M:%S %Z %Y");
//are equivalent ways of returning the current time in the default format used by the UNIX date command.</langsyntaxhighlight>
See [https://asymptote.sourceforge.io/doc/Data-types.html time() in the Asymptote manual].
 
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">FormatTime, t
MsgBox,% t</langsyntaxhighlight>
{{out}}
<pre>
Line 585:
 
=={{header|AutoIt}}==
<langsyntaxhighlight lang="autoit">MsgBox(0,"Time", "Year: "&@YEAR&",Day: " &@MDAY& ",Hours: "& @HOUR & ", Minutes: "& @MIN &", Seconds: "& @SEC)</langsyntaxhighlight>
{{out}}
<pre>
Line 593:
=={{header|Avail}}==
The method <code>now</code> retrieves the current timestamp.
<syntaxhighlight lang Avail="avail">Print: “now”;</langsyntaxhighlight>
 
=={{header|AWK}}==
'''One-liner:'''
{{works with|Gawk}}
<langsyntaxhighlight lang="awk">$ awk 'BEGIN{print systime(),strftime()}'</langsyntaxhighlight>
{{out}}
<pre>1242401632 Fri May 15 17:33:52 2009</pre>
Line 604:
'''Solution for other awk-versions:'''
{{works with|awk}}
<langsyntaxhighlight lang="awk">
function dos_date( cmd,d,t,x) { # under MS Windows
# cmd = "DATE /T"
Line 625:
#print systime(), strftime() # gawk only
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 634:
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="qbasic">' BaCon time
n = NOW
PRINT n, " seconds since January 1st, 1970"
PRINT YEAR(n), MONTH(n), DAY(n) FORMAT "%04d/%02d/%02d "
PRINT HOUR(n), MINUTE(n), SECOND(n) FORMAT "%02d:%02d:%02d\n"</langsyntaxhighlight>
{{out}}
<pre>
Line 648:
 
This shows the system time in seconds since midnight.
<syntaxhighlight lang ="qbasic">PRINT TIMER</langsyntaxhighlight>
 
This shows the time in human-readable format (using a 24-hour clock):
<syntaxhighlight lang ="qbasic">PRINT TIME$</langsyntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 670:
'''Code Examples'''
 
<langsyntaxhighlight lang="commodorebasic">1 rem time since last reset
5 print chr$(147);chr$(14);
10 t$=ti$
Line 683:
70 print "Press any key to quit."
80 get k$:if k$="" then goto 10
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="commodorebasic">5 rem set time to current time of day
10 print chr$(147);
20 input "Enter hour of day (0-23)";h$
Line 698:
85 print:print "Press any key to end."
90 get k$:if k$="" then 80
100 end</langsyntaxhighlight>
 
 
Line 713:
'''Code Example - Commodore 64/128 Only'''
 
<langsyntaxhighlight lang="commodorebasic">1 rem read and set cia time of day clock
2 rem rosetta code commodore 64/128 example
10 print chr$(147);chr$(14)
Line 780:
495 poke tr,0 :rem set 1/10 starts clock
497 b=1
499 print chr$(147):return</langsyntaxhighlight>
 
 
=={{header|BASIC256}}==
<langsyntaxhighlight BASIC256lang="basic256">print month+1; "-"; day; "-"; year
# returns system date in format: mm-dd-yyyy
 
print hour; ":"; minute; ":"; second
# returns system time in format: hh:mm:ss</langsyntaxhighlight>
 
 
Line 796:
 
Both <tt>date</tt> and <tt>time</tt> have a <tt>/t</tt> argument which makes them output only the value instead of prompting for a new one as well.
{{works with|Windows NT}}<langsyntaxhighlight lang="dos">date /t
time /t</langsyntaxhighlight>Furthermore there are two pseudo-variables <tt>%DATE%</tt> and <tt>%TIME%</tt>:
{{works with|Windows NT|4}}<syntaxhighlight lang ="dos">echo %DATE% %TIME%</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> PRINT TIME$</langsyntaxhighlight>Outputs the date and time. To output only the time:<langsyntaxhighlight lang="bbcbasic"> PRINT RIGHT$(TIME$,8)</langsyntaxhighlight>
 
=={{header|BQN}}==
The system value <code>•UnixTime</code> whenever called, gives time between the unix epoch the time the function was called, where the Unix epoch is 1970-01-01 00:00:00 UTC. [https://github.com/mlochbaum/bqn-libs/blob/master/datetime.bqn bqn-libs/datetime.bqn] has some functions for the manipulation of the given timestamp.
 
<syntaxhighlight lang ="bqn">•Show •UnixTime @</langsyntaxhighlight>
 
=={{header|C}}==
This probably isn't the best way to do this, but it works.
It shows system time as "Www Mmm dd hh:mm:ss yyyy", where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.<langsyntaxhighlight lang="c">#include<time.h>
#include<stdio.h>
#include<stdlib.h>
Line 817:
printf("%s", ctime(&my_time));
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang ="csharp">Console.WriteLine(DateTime.Now);</langsyntaxhighlight>
 
=={{header|C++}}==
to be compiled under linux with g++ -lboost_date_time systemtime.cpp -o systemtime( or whatever you like)
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
 
Line 831:
std::cout << to_simple_string( t ) << std::endl ;
return 0 ;
}</langsyntaxhighlight>
 
===C++ 11===
<langsyntaxhighlight lang="cpp">#include <chrono>
#include <ctime> //for conversion std::ctime()
#include <iostream>
Line 841:
auto timenow = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::cout << std::ctime(&timenow) << std::endl;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 848:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(import '[java.util Date])
; the current system date time string
(print (new Date))
Line 854:
(print (. (new Date) getTime))
; or
(print (System/currentTimeMillis))</langsyntaxhighlight>
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">start_up = proc ()
stream$putl(stream$primary_output(), date$unparse(now()))
end start_up</langsyntaxhighlight>
{{out}}
<pre>19 December 2021 01:50:11</pre>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> WORKING-STORAGE SECTION.
01 WS-CURRENT-DATE-FIELDS.
05 WS-CURRENT-DATE.
Line 878:
PROCEDURE DIVISION.
MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-FIELDS.</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
=== Script Based CFML ===
<langsyntaxhighlight lang="cfm"><cfscript>
// Date Time
currentTime = Now();
Line 892:
utcDate = dateConvert( "local2utc", currentTime );
writeOutput( utcDate.getTime() );
</cfscript></langsyntaxhighlight>
{{Output}}
<pre>
Line 900:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(multiple-value-bind (second minute hour day month year) (get-decoded-time)
(format t "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" year month day hour minute second))</langsyntaxhighlight>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="ruby"># current time in system's time zone:
Time.local
 
Line 912:
# monotonic time (useful for measuring elapsed time)
Time.monotonic
</syntaxhighlight>
</lang>
 
=={{header|D}}==
Line 920:
Days are used in the example,
but lower units are available, with the lowest being nanoseconds (nanos field).
<langsyntaxhighlight Dlang="d">Stdout(Clock.now.span.days / 365).newline;</langsyntaxhighlight>
 
=={{header|DBL}}==
<langsyntaxhighlight DBLlang="dbl">XCALL TIME (D6) ;D6=hhmmss</langsyntaxhighlight>
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ start_time = f$time()
$ wait 0::10
$ end_time = f$time()
$ write sys$output "start time was ", start_time
$ write sys$output "end time was ", end_time
$ write sys$output "delta time is ", f$delta_time( start_time, end_time )</langsyntaxhighlight>
{{out}}
<pre>$ @system_time
Line 943:
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">lblDateTime.Caption := FormatDateTime('dd mmmm yyyy hh:mm:ss', Now);</langsyntaxhighlight>This populates a label with the date
 
=={{header|DWScript}}==
<langsyntaxhighlight lang="delphi">PrintLn(FormatDateTime('dd mmmm yyyy hh:mm:ss', Now));</langsyntaxhighlight>
 
=={{header|E}}==
<syntaxhighlight lang ="e">println(timer.now())</langsyntaxhighlight>
 
The value is the number of milliseconds since 1970.
Line 955:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">print time_strtimestr sys_timesystime</langsyntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="ecstasy">
module WhatTimeIsIt {
@Inject Clock clock;
@Inject Console console;
 
void run() {
console.print($"current time: {clock.now}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
current time: 2024-04-30 19:40:57.124
</pre>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import extensions;
import system'calendar;
Line 965 ⟶ 982:
{
console.printLine(Date.Now);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 972 ⟶ 989:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">:os.timestamp # => {MegaSecs, Secs, MicroSecs}
:erlang.time # => {Hour, Minute, Second}
:erlang.date # => {Year, Month, Day}
Line 979 ⟶ 996:
 
:calendar.local_time # => {{Year, Month, Day}, {Hour, Minute, Second}}
:calendar.universal_time # => {{Year, Month, Day}, {Hour, Minute, Second}}</langsyntaxhighlight>
It is also guaranteed that subsequent calls to this BIF returns continuously increasing values. Hence, the return value from <code>:erlang.now()</code> can be used to generate unique time-stamps, and if it is called in a tight loop on a fast machine the time of the node can become skewed.
<syntaxhighlight lang ="elixir">:random.seed(:erlang.now)</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<langsyntaxhighlight Lisplang="lisp">(message "%s" (current-time-string))
;; => "Wed Oct 14 22:21:05 1987"</syntaxhighlight>
=>
"Wed Oct 14 22:21:05 1987"</lang>
 
<code>current-time</code> is the main programmatic interface, with various functions available to format or operate on the time values list it gives.
 
=={{header|Erlang}}==
By default, Erlang timestamps are turned in the {megasecs, secs, microsecs} format.<langsyntaxhighlight lang="erlang">1> os:timestamp().
{1250,222584,635452}</langsyntaxhighlight>
These can be changed with the calendar module:<langsyntaxhighlight lang="erlang">2> calendar:now_to_datetime(os:timestamp()).
{{2009,8,14},{4,3,24}}
3> calendar:now_to_universal_time(os:timestamp()).
{{2009,8,14},{4,3,40}}
4> calendar:now_to_local_time(os:timestamp()).
{{2009,8,14},{0,7,01}}</langsyntaxhighlight>Note that you will often encounter the function <tt>erlang:now/0</tt> giving a time similar to the system time. However, <tt>erlang:now/0</tt> may get delayed if the system time changes suddenly (i.e.: coming back from sleep mode). The delay is in place to make sure <tt>receive</tt> clauses that are millisecond-sensitive do not get false timeouts.
 
=={{header|Excel}}==
NOW() returns the date and time to the minute.
Type in a cell :<langsyntaxhighlight Excellang="excel">=NOW()</langsyntaxhighlight>
{{out}}
<pre>9-8-2013 17:33</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">printfn "%s" (System.DateTime.Now.ToString("u"))</langsyntaxhighlight>
{{out}}
<pre>
Line 1,014 ⟶ 1,030:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USE: calendar
 
now .</langsyntaxhighlight>
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">
/* Added by Aykayayciti Earl Lamont Montgomery
April 10th, 2018 */
 
> CurrentTime().toString()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,034 ⟶ 1,050:
<tt>DateTime.now</tt> returns the current time, which can then be formatted into different styles. For example, <tt>toJava</tt> returns the current time in milliseconds since 1 Jan 1970.
 
<tt>DateTime.nowTicks</tt> returns the number of nanoseconds since 1 Jan 2000 UTC.<langsyntaxhighlight lang="fantom">fansh> DateTime.nowTicks
351823905158000000
fansh> DateTime.now
2011-02-24T00:51:47.066Z London
fansh> DateTime.now.toJava
1298508885979</langsyntaxhighlight>
 
=={{header|Forth}}==
Line 1,052 ⟶ 1,068:
{{works with|VFX Forth}}
{{works with|MacForth}}
<langsyntaxhighlight lang="forth">[UNDEFINED] MS@ [IF] \ Win32Forth (rolls over daily)
[DEFINED] ?MS [IF] ( -- ms )
: ms@ ?MS ; \ iForth
Line 1,069 ⟶ 1,085:
[THEN] [THEN] [THEN] [THEN] [THEN] [THEN] [THEN]
 
MS@ . \ print millisecond counter</langsyntaxhighlight>
 
=={{header|Fortran}}==
In ISO Fortran 90 or later, use the SYSTEM_CLOCK intrinsic subroutine:<langsyntaxhighlight lang="fortran">integer :: start, stop, rate
real :: result
Line 1,084 ⟶ 1,100:
call system_clock( stop )
print *, "elapsed time: ", real(stop - start) / real(rate)</langsyntaxhighlight>In ISO Fortran 95 or later, use the CPU_TIME intrinsic subroutine:<langsyntaxhighlight lang="fortran">real :: start, stop
real :: result
Line 1,094 ⟶ 1,110:
call cpu_time( stop )
print *, "elapsed time: ", stop - start</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Print Date + " " + Time '' returns system date/time in format : mm-dd-yyyy hh:mm:ss
Sleep</langsyntaxhighlight>
 
=={{header|Frink}}==
<syntaxhighlight lang ="frink">println[now[]]</langsyntaxhighlight>
{{out}}
<pre>AD 2020-06-24 PM 06:37:01.326 (Wed) Mountain Daylight Time</pre>
 
=={{header|FutureBasic}}==
Time can be configured from simple to specialized in FB. Here's the simplest way.
<syntaxhighlight lang="futurebasic">window 1
print time
print time(@"hh:mm:ss" )
print time(@"h:mm a" )
print time(@"h:mm a zzz")
HandleEvents</syntaxhighlight>
{{output}}
<pre>
19:30:58
07:30:58
7:30 PM
7:30 PM EDT
</pre>
 
More accurate timing...
<syntaxhighlight lang="futurebasic">window 1
 
print fn CFAbsoluteTimeGetCurrent
print fn CACurrentMediaTime
print fn ProcessInfoSystemUptime
 
HandleEvents</syntaxhighlight>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=f061cc0cf175496b37bbcd14bd1e7058 Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
 
Print Format(Now, "dddd dd mmmm yyyy hh:nn:ss")
 
End</langsyntaxhighlight>
Output:
<pre>
Line 1,120 ⟶ 1,161:
 
=={{header|Genie}}==
<langsyntaxhighlight lang="genie">[indent=4]
 
init
var now = new DateTime.now_local()
print now.to_string()</langsyntaxhighlight>
 
{{out}}
Line 1,132 ⟶ 1,173:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "time"
Line 1,141 ⟶ 1,182:
fmt.Println(t) // default format
fmt.Println(t.Format("Mon Jan 2 15:04:05 2006")) // some custom format
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
Solution (based on [[#Java|Java]] solution).<langsyntaxhighlight lang="groovy">def nowMillis = new Date().time
println 'Milliseconds since the start of the UNIX Epoch (Jan 1, 1970) == ' + nowMillis</langsyntaxhighlight>
{{out}}
Milliseconds since the start of the UNIX Epoch (Jan 1, 1970) == 1243395159250
Line 1,151 ⟶ 1,192:
=={{header|GUISS}}==
 
We can only show the clock, but this might not be set to system time:<syntaxhighlight lang ="guiss">Taskbar</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import System.Time
(getClockTime, toCalendarTime, formatCalendarTime)
 
Line 1,164 ⟶ 1,205:
print ct -- print default format, or
cal <- toCalendarTime ct
putStrLn $ formatCalendarTime defaultTimeLocale "%a %b %e %H:%M:%S %Y" cal</langsyntaxhighlight>
 
or with the time library:
<langsyntaxhighlight lang="haskell">import Data.Time (getZonedTime, formatTime, defaultTimeLocale)
 
main :: IO ()
Line 1,173 ⟶ 1,214:
zt <- getZonedTime
print zt -- print default format, or
putStrLn $ formatTime defaultTimeLocale "%a %b %e %H:%M:%S %Y" zt</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight HicEstlang="hicest">seconds_since_midnight = TIME() ! msec as fraction
 
seconds_since_midnight = TIME(Year=yr, Day=day, WeekDay=wday, Gregorian=gday)
! other options e.g. Excel, YYYYMMDD (num or text)</langsyntaxhighlight>
 
=={{header|HolyC}}==
<langsyntaxhighlight lang="holyc">CDateStruct ds;
Date2Struct(&ds, Now + local_time_offset);
 
Print("%04d-%02d-%02d %02d:%02d:%02d\n", ds.year, ds.mon, ds.day_of_mon, ds.hour, ds.min, ds.sec);
</syntaxhighlight>
</lang>
 
=={{header|Hoon}}==
The time of the current system event is made available on the subject in most contexts as <tt>now</tt>.
 
<syntaxhighlight lang Hoon="hoon">now</langsyntaxhighlight>{{out}}
~2016.7.24..01.25.02..0f8e
 
Line 1,197 ⟶ 1,238:
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Uniconlang="unicon">procedure main()
 
write("&time - milliseconds of CPU time = ",&time)
Line 1,207 ⟶ 1,248:
write("&now - time in seconds since the epoch = ", &now) # Unicon only
 
end</langsyntaxhighlight>
 
{{out}}
Line 1,242 ⟶ 1,283:
 
=={{header|Io}}==
<syntaxhighlight lang ="io">Date now println</langsyntaxhighlight>{{out}}
2008-08-26 00:15:52 EDT
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang IS="is-BASICbasic">100 PRINT TIME$</langsyntaxhighlight>
 
=={{header|J}}==
The external verb <code>6!:0</code> returns a six-element floating-point array in which the elements correspond to year, month, day, hour, minute, and second. Fractional portion of second is given to thousandths.<langsyntaxhighlight lang="j"> 6!:0 ''
2008 1 23 12 52 10.341</langsyntaxhighlight>
 
A formatted string representation of the current time can also be returned:<langsyntaxhighlight lang="j"> 6!:0 'YYYY-MM-DD hh:mm:ss.sss'
2009-08-26 10:38:53.171</langsyntaxhighlight>
 
=={{header|Java}}==
{{works with|Java|1.5+}}
<langsyntaxhighlight lang="java">public class SystemTime{
public static void main(String[] args){
System.out.format("%tc%n", System.currentTimeMillis());
}
}</langsyntaxhighlight>{{out}}
Mon Jun 21 13:02:19 BST 2010
 
Or using a <code>Date</code> object:<lang java>import java.util.Date;
Or using <code>ZonedDateTime</code> object:<syntaxhighlight lang="java">import java.time.ZonedDateTime;
 
public class SystemTime{
public static void main(String[] args){
Datevar now = new DateZonedDateTime.now();
System.out.println(now); // string representation
 
System.out.println(now.getTime()); // Unix time (# of milliseconds since Jan 1 1970)
//System.currentTimeMillis() returns the same value
}
}</langsyntaxhighlight>
 
Alternately, you can use a <tt>Calendar</tt> object, which allows you to retrieve specific fields of the date.
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">console.log(new Date()) // => Sat, 28 May 2011 08:22:53 GMT
console.log(Date.now()) // => 1306571005417 // Unix epoch</syntaxhighlight>
 
=={{header|Joy}}==
<lang javascript>console.log(new Date()) // => Sat, 28 May 2011 08:22:53 GMT
<syntaxhighlight lang="joy">time localtime "%T\n" strftime putchars.</syntaxhighlight>
console.log(Date.now()) // => 1306571005417 // Unix epoch</lang>
 
=={{header|jq}}==
{{works with|jq |1.5}}
 
<langsyntaxhighlight lang="sh">$ jq -n 'now | [., todate]'
[
1437619000.970498,
"2015-07-23T02:36:40Z"
]</langsyntaxhighlight>
 
"now" reports the number of seconds since the beginning of the [https://en.wikipedia.org/wiki/Unix_epoch Unix epoch].
Line 1,296 ⟶ 1,335:
Jsish does not implement the standard ECMAScript Date module but provides '''strftime''' and '''strptime'''.
 
<syntaxhighlight lang ="javascript">console.log(strftime());</langsyntaxhighlight>
 
{{out}} using interactive echo of results
Line 1,305 ⟶ 1,344:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
ts = time()
 
println("The system time is (in ISO 8601 format):")
println(strftime(" %F %T %Z", ts))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,319 ⟶ 1,358:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
println("%tc".format(System.currentTimeMillis()))
}
</syntaxhighlight>
</lang>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{date}
-> 2021 02 22 07 23 12
</syntaxhighlight>
</lang>
 
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">date->format('%Q %T')
date->asInteger</langsyntaxhighlight>{{out}}
2013-11-02 11:47:27
1383407747
Line 1,344 ⟶ 1,383:
By default, LFE timestamps are turned in the <code>#(megasecs secs microsecs)</code> format.
 
<langsyntaxhighlight lang="lisp">
> (os:timestamp)
#(1423 786308 145798)
</syntaxhighlight>
</lang>
 
These can be changed to the more common date/time stamp with the <code>calendar</code> module:
 
<langsyntaxhighlight lang="lisp">
> (calendar:now_to_datetime (os:timestamp))
#(#(2015 2 13) #(0 12 18))
</syntaxhighlight>
</lang>
 
Locale taken into account:
 
<langsyntaxhighlight lang="lisp">
> (calendar:now_to_universal_time (os:timestamp))
#(#(2015 2 13) #(0 13 51))
> (calendar:now_to_local_time (os:timestamp))
#(#(2015 2 12) #(16 14 26))
</syntaxhighlight>
</lang>
 
Note that you will often encounter the function <code>erlang:now/0</code> giving a time similar to the system time. However, <code>erlang:now/0</code> may get delayed if the system time changes suddenly (i.e.: coming back from sleep mode). The delay is in place to ensure that <code>receive</code> clauses which are millisecond-sensitive do not get false timeouts.
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">print time$() 'time now as string "16:21:44"
print time$("seconds") 'seconds since midnight as number 32314
print time$("milliseconds") 'milliseconds since midnight as number 33221342
print time$("ms") 'milliseconds since midnight as number 33221342</langsyntaxhighlight>
 
=={{header|LIL}}==
The '''system''' command is provided in the lil shell. On GNU/Linux:
<langsyntaxhighlight lang="tcl">print [system date]; print [system date +%s.%N]</langsyntaxhighlight>
 
<pre>Fri Aug 23 20:50:08 EDT 2019
Line 1,382 ⟶ 1,421:
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">put time()
-- "03:45"
 
Line 1,396 ⟶ 1,435:
-- milliseconds since last boot, due to higher resolution better suited for random number seeding
put _system.milliseconds
-- 41746442</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<syntaxhighlight lang LiveCode="livecode">put the system time</langsyntaxhighlight>
 
=={{header|Locomotive Basic}}==
The variable "time" contains the time elapsed since last system start or reset. Each unit equals 1/300 s.<langsyntaxhighlight lang="locobasic">print time
print time/300;"s since last reboot"</langsyntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
Other Logo variants might have a built-in command, but UCB Logo must access the Unix shell to get time.<langsyntaxhighlight lang="logo">
to time
output first first shell [date +%s]
Line 1,414 ⟶ 1,453:
make "start time
wait 300 ; 60ths of a second
print time - :start ; 5</langsyntaxhighlight>
 
=={{header|Lua}}==
<syntaxhighlight lang ="lua">print(os.date())</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
print str$(now,"long time"), time$(now)
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Different ways of doing this, here are 2 most common:<langsyntaxhighlight Mathematicalang="mathematica">Print[DateList[]]
Print[AbsoluteTime[]]</langsyntaxhighlight>DateList will return the list {year,month,day,hour,minute,second} where all of them are integers except for second; that is a float. AbsoluteTime gives the total number of seconds since january 1st 1900 in your time zone.
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<syntaxhighlight lang MATLAB="matlab"> datestr(now)</langsyntaxhighlight><pre>ans =
13-Aug-2010 12:59:56</pre><syntaxhighlight lang MATLAB="matlab"> clock</langsyntaxhighlight><pre>ans =
2010 8 13 12 59 56.52</pre>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">/* Time and date in a formatted string */
timedate();
"2012-08-27 20:26:23+10:00"
Line 1,445 ⟶ 1,484:
/* Time in seconds since Maxima was started */
elapsed_real_time();
elapsed_run_time();</langsyntaxhighlight>
 
=={{header|Microsoft Small Basic}}==
Date and time follows the user's locale.
<syntaxhighlight lang="smallbasic">TextWindow.WriteLine(Clock.Date + " " + Clock.Time)</syntaxhighlight>
{{out}}
<pre>02/12/2022 8:27:15 PM
Press any key to continue...</pre>
 
=={{header|min}}==
{{works with|min|0.27.1}}
<syntaxhighlight lang ="min">now datetime puts!</langsyntaxhighlight>
{{out}}
<pre>
Line 1,457 ⟶ 1,503:
=={{header|Modula-2}}==
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<langsyntaxhighlight lang="modula2">
MODULE Mytime;
 
Line 1,479 ⟶ 1,525:
WriteLn;
END Mytime.
</syntaxhighlight>
</lang>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE MyTime EXPORTS Main;
 
IMPORT IO, FmtTime, Time;
Line 1,488 ⟶ 1,534:
BEGIN
IO.Put("Current time: " & FmtTime.Long(Time.Now()) & "\n");
END MyTime.</langsyntaxhighlight>{{out}}
Current time: Tue Dec 30 20:50:07 CST 2008
 
=={{header|MUMPS}}==
System time since midnight (in seconds) is kept in the second part of the system variable $HOROLOG.<langsyntaxhighlight MUMPSlang="mumps">SYSTIME
NEW PH
SET PH=$PIECE($HOROLOG,",",2)
WRITE "The system time is ",PH\3600,":",PH\60#60,":",PH#60
KILL PH
QUIT</langsyntaxhighlight>Usage:<pre>USER>D SYSTIME^ROSETTA
The system time is 22:55:44</pre>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">import Nanoquery.Util
println new(Date).getTime()</langsyntaxhighlight>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
<doc>
<h2>System time</h2>
Line 1,517 ⟶ 1,563:
 
var now = date_now()
$print(now, " ", date_format(now, "%T"), "\n")</langsyntaxhighlight>
{{out}}
<pre>prompt$ nekoc system-time.neko
Line 1,524 ⟶ 1,570:
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">System.Console.Write(System.DateTime.Now);</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight lang="netrexx">
import java.text.SimpleDateFormat
say SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS").format(Date())</langsyntaxhighlight>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">> (date)
"Sun Sep 28 20:17:55 2014"</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import times
 
echo getDateStr()
echo getClockStr()
echo getTime()
echo now() # shorthand for "getTime().local"</langsyntaxhighlight>
{{out}}
<pre>2021-04-21
Line 1,549 ⟶ 1,595:
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">function : Time() ~ Nil {
t := Time->New();
IO.Console->GetInstance()->Print(t->GetHours())->Print(":")->Print(t->GetMinutes())->Print(":")->PrintLine(t->GetSeconds());
}</langsyntaxhighlight>
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">NSLog(@"%@", [NSDate date]);</langsyntaxhighlight>or (deprecated)<langsyntaxhighlight lang="objc">NSLog(@"%@", [NSCalendarDate calendarDate]);</langsyntaxhighlight>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">#load "unix.cma";;
open Unix;;
let {tm_sec = sec;
Line 1,569 ⟶ 1,615:
tm_yday = yday;
tm_isdst = isdst} = localtime (time ());;
Printf.printf "%04d-%02d-%02d %02d:%02d:%02d\n" (year + 1900) (mon + 1) mday hour min sec;</langsyntaxhighlight>
 
=={{header|Oforth}}==
Line 1,575 ⟶ 1,621:
System.tick is used to retrieve a tick from the system in order to compute small intervals of time. It is used by #bench method to compute duration of a runnable (unit is micro second).
 
<langsyntaxhighlight Oforthlang="oforth">System.tick println
#[ #sqrt 1000000 seq map sum println ] bench</langsyntaxhighlight>
 
{{out}}
Line 1,588 ⟶ 1,634:
Integer returned by System.localTime allows to create a Date object.
 
<langsyntaxhighlight Oforthlang="oforth">import: date
 
System.localTime dup println asDate println drop drop</langsyntaxhighlight>
 
{{out}}
Line 1,599 ⟶ 1,645:
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">{Show {OS.time}} %% posix time (seconds since 1970-01-01)
{Show {OS.gmTime}} %% current UTC as a record
{Show {OS.localTime}} %% current local time as record
Line 1,606 ⟶ 1,652:
%% When did posix time reach 1 billion?
{Show {OsTime.gmtime 1000000000}}
{Show {OsTime.localtime 1000000000}}</langsyntaxhighlight>{{out}}
1263347902
time(hour:1 isDst:0 mDay:13 min:58 mon:0 sec:22 wDay:3 yDay:12 year:110)
Line 1,616 ⟶ 1,662:
For timing the <code>gettime</code> is usually used, which measures CPU time rather than walltime. But to get the raw time you'll need a system call
 
<langsyntaxhighlight lang="parigp">system("date")</langsyntaxhighlight>
 
Direct access to the C library <code>time()</code> function can be had by an <code>install()</code>, and it should be faster than running the date program.
 
<langsyntaxhighlight lang="parigp">install(time, "lf");
t = time();
print(t); \\ integer seconds since the epoch (usually 1 Jan 1970)</langsyntaxhighlight>
 
<code>install()</code> can't give the higher resolution C library time functions like <code>gettimeofday()</code> or <code>clock_gettime()</code> but some further C code could put their results into a Pari integer or rational suitable for <code>install()</code> in GP.
Line 1,628 ⟶ 1,674:
=={{header|Pascal}}==
{{works with|Extended Pascal}}
Extended Pascal, as defined by the ISO standard 10206, defines a <tt>record</tt> data type that at least identifies the following members:<langsyntaxhighlight Pascallang="pascal">type
timeStamp = packed record
dateValid: Boolean;
Line 1,638 ⟶ 1,684:
minute: 0..59;
second: 0..59;
end;</langsyntaxhighlight>A variable of this built-in data type can be populated with the <tt>getTimeStamp</tt> procedure as demostrated below:<langsyntaxhighlight Pascallang="pascal">program systemTime(output);
var
ts: timeStamp;
Line 1,653 ⟶ 1,699:
writeLn(time(ts));
end;
end.</langsyntaxhighlight>
{{out}}
{{CURRENTTIME}}:42
Line 1,661 ⟶ 1,707:
 
=={{header|Perl}}==
Simple localtime use in scalar context.<langsyntaxhighlight lang="perl">print scalar localtime, "\n";</langsyntaxhighlight>{{out}}
Thu Jan 24 11:23:30 2008
 
localtime use in array context.<langsyntaxhighlight lang="perl">($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
printf("%04d-%02d-%02d %02d:%02d:%02d\n", $year + 1900, $mon + 1, $mday, $hour, $min, $sec</langsyntaxhighlight>
{{out}}
2008-01-24 11:23:30
 
The same using DateTime:<langsyntaxhighlight lang="perl">use DateTime;
my $dt = DateTime->now;
my $d = $dt->ymd;
my $t = $dt->hms;
print "$d $t\n";</langsyntaxhighlight>{{out}}
2010-03-29 19:46:26
 
localtime use in array context with [[POSIX]] strftime:<langsyntaxhighlight lang="perl">use POSIX qw(strftime);
 
$now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
print "$now_string\n";</langsyntaxhighlight>Output (with cs_CZ.UTF-8 locale):
<pre>Čt led 24 11:23:30 2008</pre>Using the [http://search.cpan.org/perldoc?DateTime DateTime] module:<langsyntaxhighlight lang="perl">use DateTime;
my $dt = DateTime->now;
say $dt->iso8601();
say $dt->year_with_christian_era();
say $dt->year_with_secular_era();
# etc.</langsyntaxhighlight>Unix epoch:<syntaxhighlight lang ="perl">print time;</langsyntaxhighlight>{{out}}
1280473609
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">include</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: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"Dddd, Mmmm dth, YYYY, h:mm:ss pm"</span><span style="color: #0000FF;">)</span>
Line 1,697 ⟶ 1,743:
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0.9</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,707 ⟶ 1,753:
 
=={{header|Phixmonti}}==
<langsyntaxhighlight Phixmontilang="phixmonti">def printList len for get print endfor enddef
 
time
 
"Actual time is " swap 1 get " hour, " rot 2 get " minutes, " rot 3 get nip " seconds, "
"and elapsed " msec " seconds of running time." 10 tolist printList</langsyntaxhighlight>
 
=={{header|PHP}}==
Seconds since the Unix epoch:<langsyntaxhighlight lang="php">echo time(), "\n";</langsyntaxhighlight>
 
Microseconds since the Unix epoch:<langsyntaxhighlight lang="php">echo microtime(), "\n";</langsyntaxhighlight>Formatted time:<langsyntaxhighlight lang="php">echo date('D M j H:i:s Y'), "\n"; // custom format; see format characters here:
// http://us3.php.net/manual/en/function.date.php
echo date('c'), "\n"; // ISO 8601 format
echo date('r'), "\n"; // RFC 2822 format
echo date(DATE_RSS), "\n"; // can also use one of the predefined formats here:
// http://us3.php.net/manual/en/class.datetime.php#datetime.constants.types</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<syntaxhighlight lang PicoLisp="picolisp">(stamp)</langsyntaxhighlight>{{out}}
-> "2010-02-19 15:14:06
 
=={{header|Pike}}==
<langsyntaxhighlight Pikelang="pike">write( ctime(time()) );</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,736 ⟶ 1,782:
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">put (datetime()); /* writes out the date and time */
/* The time is given to thousandths of a second, */
/* in the format hhmiss999 */
put (time()); /* gives the time in the format hhmiss999. */</langsyntaxhighlight>
 
=={{header|PowerShell}}==
Using a cmdlet:<langsyntaxhighlight lang="powershell">Get-Date</langsyntaxhighlight>or using .NET classes and properties:<langsyntaxhighlight lang="powershell">[DateTime]::Now</langsyntaxhighlight>
 
 
=={{header|Prolog}}==
==={{header|GNU_Prolog}}===
{{works with|GNU Prolog}}
<syntaxhighlight lang="prolog">date_time(H).</syntaxhighlight>
{{out}}
<pre>H = dt(2022,1,23,21,37,16)</pre>
 
==={{header|B-Prolog}}===
{{works with|B-Prolog}}
<syntaxhighlight lang="prolog">time(H,M,S)</syntaxhighlight>
{{out}}
<pre>
H = 21
M = 37
S = 16
</pre>
 
{{works with|B-Prolog}}
<syntaxhighlight lang="prolog">date(Y,M,D)</syntaxhighlight>
{{out}}
<pre>
Y = 2022
M = 1
D = 23
</pre>
 
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">time=Date() ; Unix timestamp
time$=FormatDate("%mm.%dd.%yyyy %hh:%ii:%ss",time)
 
; following value is only reasonable accurate, on Windows it can differ by +/- 20 ms
ms_counter=ElapsedMilliseconds()
; could use API like QueryPerformanceCounter_() on Windows for more accurate values</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import time
print time.ctime()</langsyntaxhighlight>
 
=={{header|Q}}==
Date & time are accessible via the virtual .z namespace. lowercase names are UTC, uppercase are local:<langsyntaxhighlight lang="q">q).z.D
2010.01.25
q).z.N
Line 1,768 ⟶ 1,842:
2010.01.25T14:17:48.711
q).z.z
2010.01.25T19:17:59.445</langsyntaxhighlight>
 
=={{header|Quackery}}==
<langsyntaxhighlight Quackerylang="quackery">time 1000000 / echo say " seconds since the Unix epoch."</langsyntaxhighlight>
'''Output'''
<pre>1610201941 seconds since the Unix epoch.</pre>
Line 1,777 ⟶ 1,851:
=={{header|R}}==
{{works with|R|2.8.1}}
Note that this is output as a standard style string.<syntaxhighlight lang R="r">Sys.time()</langsyntaxhighlight>{{out}}
[1] "2009-07-27 15:27:04 PDT"
 
Line 1,783 ⟶ 1,857:
 
The system time as a date string:
<langsyntaxhighlight lang="racket">#lang racket
(require racket/date)
(date->string (current-date))</langsyntaxhighlight>
 
Or, as seconds after midnight UTC, January 1, 1970:<langsyntaxhighlight lang="racket">#lang racket
(current-seconds)</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>say DateTime.now;
dd DateTime.now.Instant;</langsyntaxhighlight>
{{out}}
2015-11-02T13:34:09+01:00
Line 1,799 ⟶ 1,873:
 
=={{header|Raven}}==
Note the use of single quotation marks for the date specifier.<syntaxhighlight lang="text">time dup print "\n" print int '%a %b %e %H:%M:%S %Y' date</langsyntaxhighlight>
{{out}}
1353352623.511231
Line 1,805 ⟶ 1,879:
 
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">now
<lang REBOL>now
print rejoin [now/year "-" now/month "-" now/day " " now/time]</langsyntaxhighlight>{{out}}
10-Dec-2009/7:43:55-5:00
2009-12-10 7:43:55
Line 1,812 ⟶ 1,886:
=={{header|Retro}}==
Displays the number of seconds since the Unix epoch:
<syntaxhighlight lang Retro="retro">time putn</langsyntaxhighlight>
 
=={{header|REXX}}==
Note that REXX only examines the first character of the option and can be in upper or lower case.
<langsyntaxhighlight lang="rexx">/*REXX program shows various ways to display the system time, including other options. */
 
say '════════════ Normal format of time'
Line 1,861 ⟶ 1,935:
say time('S')
say time('seconds') /* (same as the previous example.) */
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|:}}
<pre>
Line 1,904 ⟶ 1,978:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
/* Output:
** Sun abbreviated weekday name
Line 1,930 ⟶ 2,004:
 
See TimeList()
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
Since 1990, there is a command named <code>TICKS</code> which returns the system time in 1/8192ths of a second, using a 64-bit unsigned integer:
{{out}}
<pre>
1: #1DBC0D1698BE0h
</pre>
There is also a <code>TIME</code> command, returning the system time in a hh.mmss format:
 
'''Output:'''
1: 20.4526471679 <span style="color:grey">@ 8:45:26 PM</span>
 
=={{header|Ruby}}==
version 1.9+<langsyntaxhighlight lang="ruby">t = Time.now
 
# textual
Line 1,946 ⟶ 2,031:
# epoch time as a rational (more precision):
puts Time.now.to_r # 1424900671883862959/1000000000
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// 20210210 Rust programming solution
 
extern crate chrono;
Line 1,958 ⟶ 2,043:
println!("{}", utc.format("%d/%m/%Y %T"));
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,967 ⟶ 2,052:
{{libheader|Scala}}Ad hoc solution as [http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL] scripts:
===JDK < 8===
<syntaxhighlight lang ="scala">println(new java.util.Date)</langsyntaxhighlight>{{out}}
Sun Aug 14 22:47:42 EDT 2011
===JDK >= 8 (recommended)===
<langsyntaxhighlight lang="scala">println(java.time.LocalTime.now())</langsyntaxhighlight>{{out}}
11:32:39.002
 
=={{header|Scheme}}==
{{works with|Chicken Scheme}}<langsyntaxhighlight lang="scheme">(use posix)
(seconds->string (current-seconds))</langsyntaxhighlight>{{out}}
"Sat May 16 21:42:47 2009"
{{works with|Chez Scheme}}
<syntaxhighlight lang="scheme">(display (date-and-time)) (newline)</syntaxhighlight>
{{out}}
<pre>
Mon Jun 27 19:51:09 2022
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
 
Line 1,985 ⟶ 2,076:
begin
writeln(time(NOW));
end func;</langsyntaxhighlight>{{out}}
2009-12-07 17:09:44.687500 UTC+1
 
=={{header|SETL}}==
<langsyntaxhighlight lang="setl">$ Unix time
print(tod);
 
$ Human readable time and date
print(date);</langsyntaxhighlight>
 
{{out}}
<langsyntaxhighlight lang="setl">
1447628158908
Sun Nov 15 22:55:58 2015
</syntaxhighlight>
</lang>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby"># textual
say Time.local.ctime; # => Thu Mar 19 15:10:41 2015
 
Line 2,009 ⟶ 2,100:
 
# epoch time with fractional seconds
say Time.micro_sec; # => 1426770641.68409</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}<syntaxhighlight lang ="smalltalk">DateTime now displayNl.</langsyntaxhighlight>{{out}}
2011-08-10T00:43:36-0-7:00
 
{{works with|Pharo}}{{works with|Smalltalk/X}}<syntaxhighlight lang ="smalltalk">DateAndTime now</langsyntaxhighlight>{{out}}
2011-08-16T19:40:37-03:00
 
=={{header|SNOBOL4}}==
<langsyntaxhighlight SNOBOL4lang="snobol4"> OUTPUT = DATE()
END</langsyntaxhighlight>{{out}}
03/30/2010 20:58:09
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">hour,min,sec = #.now()
day,month,year = #.today()
 
#.output(#.str(hour,"00:"),#.str(min,"00:"),#.str(sec,"00.000"))
#.output(day,".",#.str(month,"00"),".",year)</langsyntaxhighlight>
{{out}}
<pre>
Line 2,037 ⟶ 2,128:
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
<langsyntaxhighlight lang="sql pl">
SELECT CURRENT DATE, CURRENT TIME, CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,054 ⟶ 2,145:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">print (Date.toString (Date.fromTimeLocal (Time.now ())) ^ "\n")</langsyntaxhighlight>
 
=={{header|Stata}}==
 
<langsyntaxhighlight lang="stata">di c(current_date)
di c(current_time)</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
var ⌚️ = NSDate()
println(⌚️)</langsyntaxhighlight>{{out}}
2014-06-22 20:43:42 +0000
 
=={{header|Tcl}}==
This uses a timestamp that is a number of seconds since the start of the UNIX Epoch.<syntaxhighlight lang ="tcl">puts [clock seconds]</langsyntaxhighlight>
More readable forms may be created by formatting the time:<langsyntaxhighlight lang="tcl">puts [clock format [clock seconds]]</langsyntaxhighlight>
 
=={{header|TI-89 BASIC}}==
<langsyntaxhighlight lang="ti89b">■ getTime() {13 28 55}
■ getDate() {2009 8 13}</langsyntaxhighlight>Note that the system clock can be turned off, in which case the value returned will remain constant. <tt>isClkOn()</tt> can be used to check it.
 
 
=={{header|True BASIC}}==
<langsyntaxhighlight lang="qbasic">PRINT DATE$
! returns system date in format: “YYYYMMDD”.
! Here YYYY is the year, MM is the month number, and DD is the day number.
Line 2,084 ⟶ 2,175:
PRINT TIME$
! returns system time in format: “HH:MM:SS”.
END</langsyntaxhighlight>
 
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
time=time()
PRINT time</langsyntaxhighlight>{{out}}
2011-04-05 13:45:44
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">date # Thu Dec 3 15:38:06 PST 2009
 
date +%s # 1259883518, seconds since the epoch, like C stdlib time(0)</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa"># outputs time in milliseconds
import "time"
out (time.getcurrent) endl console</langsyntaxhighlight>
 
=={{header|Ursala}}==
A library function, now, ignores its argument and returns the system time as a character string.<langsyntaxhighlight Ursalalang="ursala">#import cli
 
#cast %s
 
main = now 0</langsyntaxhighlight>{{out}}
'Fri, 26 Jun 2009 20:31:49 +0100'
This string can be converted to seconds since 1970 (ignoring leap seconds)
Line 2,115 ⟶ 2,206:
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">
var now = new DateTime.now_local();
string now_string = now.to_string();</langsyntaxhighlight>{{out}}
2011-11-12T20:23:24-0800
 
=={{header|VBA}}==
<syntaxhighlight lang VB="vb">Debug.Print Now()</langsyntaxhighlight>
{{out}}
12/12/2013 16:16:16
 
=={{header|VBScript}}==
<syntaxhighlight lang ="vb">WScript.Echo Now</langsyntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import time
 
fn main() {
t := time.Now()
println(t) // default format YYYY-MM-DD HH:MM:SS
println(t.custom_format("ddd MMM d HH:mm:ss YYYY")) // some custom format
}</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|Wren-date}}
Although Wren CLI can tell how much time has elapsed since the script started, it currently has no way of knowing what the time was then or what the time is now (in the current locale) unless the user passes the former as a command line argument.
<langsyntaxhighlight ecmascriptlang="wren">import "os" for Process
import "./date" for Date
 
var args = Process.arguments
Line 2,140 ⟶ 2,240:
var now = startTime.addMillisecs((System.clock * 1000).round)
Date.default = Date.isoTime + "|.|ttt"
System.print("Time now is %(now)")</langsyntaxhighlight>
 
{{out}}
Line 2,150 ⟶ 2,250:
 
=={{header|XPL0}}==
The intrinsics GetReg and SoftInt are used to access DOS and BIOS routines. GetReg returns the address of an array where a copy of the processor's hardware registers are stored. Values (such as $2C00 in the example) can be stored into this array. When SoftInt is called, the values in the array are loaded into the processor's registers and the specified interrupt ($21 in the example) is called.<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \include intrinsic 'code' declarations
 
proc NumOut(N); \Output a 2-digit number, including leading zero
Line 2,170 ⟶ 2,270:
NumOut(Reg(3) & $00FF); \the low byte of DX contains hundreths
CrLf(0);
]</langsyntaxhighlight>{{out}}
13:08:26.60
 
=={{header|Yabasic}}==
<syntaxhighlight lang Yabasic="yabasic">print time$</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">Time.Clock.time //-->seconds since the epoch (C/OS defined)</langsyntaxhighlight>
 
{{omit from|Axe}}
{{omit from|bc}}
{{omit from|dc}}
162

edits