System time
Output the system time (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance.
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Ada
The following example displays a date-time stamp. The time zone value is the number of minutes offset from the prime meridian.
with Ada.Calendar; use Ada.Calendar; with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones; with Ada.Text_Io; use Ada.Text_Io; procedure System_Time is Now : Time := Clock; begin Put_line(Image(Date => Now, Time_Zone => -7*60)); end System_Time;
Output:
2008-01-23 19:14:19
BASIC
Interpreter: QuickBasic 4.5
This shows the system time in POSIX time.
PRINT TIMER
Forth
Forth's only standard access to the system timers is via DATE&TIME ( -- s m h D M Y ) and MS ( n -- ) which pauses the program for at least n milliseconds. Particular Forth implementations give different access to millisecond and microsecond timers:
Interpreters: Win32Forth, GNU Forth, bigFORTH, iForth, PFE, SwiftForth, VFX Forth, MacForth
[UNDEFINED] MS@ [IF] \ Win32Forth (rolls over daily) [DEFINED] ?MS [IF] ( -- ms ) : ms@ ?MS ; \ iForth [ELSE] [DEFINED] cputime [IF] ( -- Dusec ) : ms@ cputime d+ 1000 um/mod nip ; \ gforth: Anton Ertl [ELSE] [DEFINED] timer@ [IF] ( -- Dusec ) : ms@ timer@ >us 1000 um/mod nip ; \ bigForth [ELSE] [DEFINED] gettimeofday [IF] ( -- usec sec ) : ms@ gettimeofday 1000 MOD 1000 * SWAP 1000 / + ; \ PFE [ELSE] [DEFINED] counter [IF] : ms@ counter ; \ SwiftForth [ELSE] [DEFINED] GetTickCount [IF] : ms@ GetTickCount ; \ VFX Forth [ELSE] [DEFINED] MICROSECS [IF] : ms@ microsecs 1000 UM/MOD nip ; \ MacForth [THEN] [THEN] [THEN] [THEN] [THEN] [THEN] [THEN] MS@ . \ print millisecond counter
J
The external verb 6!:0 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 accurate to thousandths.
6!:0 ''
Java
This shows the system time in POSIX time.
import java.util.Date; public class SystemTime{ public static void main(String[] args){ Date now = new Date(); System.out.println(now.getTime()); } }
Other methods are available in the Date object such as: getDay(), getHours(), getMinutes(), getSeconds(), getYear(), etc.