Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
getdate
Current datetime or POSIX timestamp from computer's clock. Datetimes from given timestamps
Syntax
curDatetime = getdate() timeStamp = getdate("s") dateTimes = getdate(timeStamps)
Arguments
- curDatetime
- vector of integers with
Index 1 2 3 4 5 6 7 8 9 10 Content year month week yearday weekday monthday hour minute second millisecond Range ≥ 1970 [1,12] [1,53] [1,366] [1,7] 1=sunday [1,31] [0,23] [0,59] [0,59] [0,999] - timeStamp
- integer number of seconds elapsed since 1970-01-01 00:00:00 UTC, excluding leap seconds, as defined by the POSIX standard (see description).
- timeStamps
- Array of positive decimal numbers representing POSIX timestamps. Negative timestamps are not accepted.
- dateTimes
- length(timeStamps)-by-10 Matrix: The row #i elements are datetime data
corresponding to timeStamps(i), as documented for
curDatetime
, except thatdateTimes(:,10)
are fractions of second in [0,1) instead of milliseconds. dateTimes are expressed in the current computer's time zone.
Description
getdate() returns the current datetime of the computer's clock, expressed in the Gregorian calendar, and for the computer's time zone + possible daylight saving offset.
Nowadays, most of computers are automatically synchronized with the legal time for the considered time zone, through time servers. Legal datetimes are synchronized on the Coordinated Universal Time (UTC), by a known time zone (and daylight saving) offset.
getdate("s") reads the computer's clock
and returns the corresponding POSIX timestamp. This corresponds to the number
of seconds elapsed since 1970-01-01 00:00:00 UTC, except that leap seconds
are not counted. Hence, if n = getdate("s")
is run at an
exact round hour, modulo(n, 3600)
will return 0 instead
of cumulated leap seconds
added since 1972 (27s, up to 2020).
getdate(timeStamps) returns the status of the
local computer's clock for the given POSIX time stamps, that may include fractional
seconds. If any, the computer's current Daylight Saving offset is never considered.
getdate(0)
will return 1970-01-01 00:00:00
only if the clock is set for the time zone = 0. Otherwise, for instance for
Scilab users living in Bélem, Brazil, UTC-3, getdate(0)
returns
1969-12-31 21:00:00, actually corresponding to 1970-01-01 00:00:00 POSIX.
Examples
D = getdate() mprintf("%d-%02d-%02d %02d:%02d:%06.3f\n", D(1), D(2), D(6:8), D(9)+D(10)/1000); x = getdate("s"); mprintf("%.2f\n", x) D = getdate(0) mprintf("%d-%02d-%02d %02d:%02d:%06.3f\n", D(1), D(2), D(6:8), D(9)+D(10)/1000);
--> D = getdate() D = 2020. 7. 30. 208. 1. 26. 23. 8. 28. 474. --> mprintf("%d-%02d-%02d %02d:%02d:%06.3f\n", D(1), D(2), D(6:8), D(9)+D(10)/1000); 2020-07-26 23:08:28.474 --> x = getdate("s"); --> mprintf("%.2f\n", x) 1595797708.00 --> D = getdate(0) D = 1970. 1. 1. 1. 5. 1. 1. 0. 0. 0. --> mprintf("%d-%02d-%02d %02d:%02d:%06.3f\n", D(1), D(2), D(6:8), D(9)+D(10)/1000); 1970-01-01 01:00:00.000
getdate("s") ignores leap seconds:
s = 1; // Expecting the next round minute @ your clock. Please be patient.. while s <> 0 D = getdate(); x = getdate("s"); s = D(9); sleep(300) // ms. To not use 100% of your processor end // If leap seconds are taken into account, they would appear here (27, in 2020): modulo(x, 60)
--> modulo(x, 60) ans = 0.
getdate([1e9, 2e9, 3e9] + 0.21) // Note the fractional seconds
--> getdate([1e9, 2e9, 3e9] + 0.21) ans = 2001. 9. 36. 252. 1. 9. 3. 46. 40. 0.21 2033. 5. 20. 138. 4. 18. 5. 33. 20. 0.21 2065. 1. 4. 24. 7. 24. 6. 20. 0. 0.21
See also
Report an issue | ||
<< etime | Temps - calendrier date horloge | now >> |