Skip to main content

DateTime():clone()

Create an independent copy of a DateTime.

Signature​

clone(): DateTime

Returns

DateTime - A new object with the same instant and timezone.

Description​

Use it before changing a value you still need. Setter methods such as add(), subtract() and set-year() change the object they are called on, so a clone keeps the original safe.

Example​

local start = DateTime()
local endTime = start:clone():add(1, "hour")
toast(start:format("HH:mm") .. " - " .. endTime:format("HH:mm"))

Compatible Version: 1.0.0.26 and up