unixEpoch
Table of Contents
Overview
The unixEpoch function calculates the number of milliseconds that have elapsed since 00:00:00 UTC on 1 January 1970.
Note:
- The date-time expression has to be in text format to enable the conversion. If any other date-type is supplied, a run-time error is encountered.
- The conversion is done based on time zones. If no timezone is provided, the timezone set in the application will be applied. If an invalid timezone is provided, the timezone is defaulted to GMT(see example below).
- If the function fails to recognise the date-time value, it will simply return the given value in text format.
- Leap seconds are not included for lapsed time
Return Type
- NUMBER
Syntax
<variable> = <dateText>.unixEpoch([<timeZone>]);
where,
Parameter | Data type | Description |
<variable> | NUMBER | Variable which will contain the returned value. |
<dateText> | TEXT | The expression which will be returned in text format. |
<timeZone> (optional) | TEXT | Time zone in which the time elapsed in milliseconds should be calculated. Value must be specified exactly as given in the TZ database name. |
Applicable Date-Time Literals
Letter | Date and Time Component |
G | Era designator |
y | Calendar year Examples: y - 2019 yy -19 yyy - 2019 dateValue = '29-Dec-2019'; |
Y | Week year Examples: Y - 2019 YY -19 YYY - 2019 dateValue = '29-Dec-2019'; |
M | Month in year Examples: M - 1 MM - 01 MMM - January |
w | Week in year |
W | Week in month |
D | Day in year |
d | Day in month |
F | Day of week in month |
E | Day name in week Examples: E - Tue EEEE - Tuesday |
u | Day number of week |
a | am/pm marker |
H | Hour in day (0-23) |
k | Hour in day (1-24) |
K | Hour in am/pm (0-11) |
h | Hour in am/pm (1-12) |
m | Minute in hour |
s | Second in minute |
S | Millisecond |
z | General time zone |
Z | RFC time zone |
X | ISO 8601 time zone |
Examples
currentDate = "03-Feb-2020 03:48:12"; indiaTime = currentDate.unixEpoch("Asia/Calcutta"); // 1580681892000 gmtMinus8 = currentDate.unixEpoch("GMT-8"); // 1580730492000 default = currentDate.unixEpoch(); // 1580730492000 utcPlus8 = currentDate.unixEpoch("UTC+8"); // 1580701692000 gmt = currentDate.unixEpoch("GMT"); // 1580701692000 indiaGMT = currentDate.unixEpoch("GMT+5:30"); // 1580681892000 est = currentDate.unixEpoch("EST"); // 1580719692000 sst = currentDate.unixEpoch("SST"); // 1580662092000 invalidTZ = currentDate.unixEpoch("Hello"); // Invalid timezone. So, defaulted to GMT. 1580701692000 invalidType = '03-Feb-2020 03:48:12'.unixEpoch("GMT"); // Run-time error