Home Contents | # clock.currentDateTime | Date/Time | Core4 Lua Commands

## SYNOPSIS

1. datetime = clock.currentDateTime()
2. datetime = clock.newDateTime(year, month, day, [hour [, minute[, second[, millisecond]]]])
3. datetime = clock.newDateTime(str)

## DESCRIPTION

Both functions create a new datetime instance. clock.currentDateTime() initializes the instance from the current system datetime, while clock.newDateTime() initializes from an arbitrary value.

Particularly, the third form takes a string str encoded in ISO8601 extended format "YYYY-MM-DDTHH:MM:SS". This is the same format as returned by tostring(datetime).
Alternatively it takes just a date "YYYY-MM-DD", then the time is assumed to be 00:00:00.

## RETURN VALUE

Returns a new datetime instance.

## NOTES

The system clock runs in the UTC time zone. If you need the local time, convert to local time using datetime:toLocal().

## EXAMPLE

> >
d = clock.newDateTime(1989,11,9) print (d)
1989-11-09T00:00:00
> >
d = clock.newDateTime("1989-11-09T00:00:00") print(d:year(), d:month(), d:day())
1989 11 9

## SEE ALSO

clock.setDateTime, clock.tzget, clock.tzset, datetime(), datetime:addDays, datetime:addMonths, datetime:addSecs, datetime:addYears, datetime:base90, datetime:date, datetime:day, datetime:daysTo, datetime:format, datetime:hour, datetime:isNull, datetime:isValid, datetime:isdst, datetime:minute, datetime:month, datetime:msec, datetime:offset, datetime:second, datetime:secsTo, datetime:set, datetime:setBase90, datetime:time, datetime:toLocal, datetime:toUTC, datetime:year, datetime:zone, tostring(datetime)