DateTime
Date and time creation, parsing, and manipulation
Dates and times. Static methods make one, instance methods compare, format and do arithmetic.
Properties
yearNumberYear component
monthNumberMonth component (1-12)
dayNumberDay of month
hourNumberHour component (0-23)
minuteNumberMinute component (0-59)
secondNumberSecond component (0-59)
weekdayStringDay name ("sunday" to "saturday")
Methods
.format(pattern)StringFormat this date using a pattern (e.g. 'yyyy-MM-dd HH:mm').
- pattern String required
.relative()StringGet a relative time string (e.g. '2 hours ago').
.countdown(options?)LiveTextTime left until this date, counting down live on the Home Screen and stopping at 0:00. Hand the result to Text(). Measured from now unless from says otherwise.
- options Any
- from DateTime | Date | number
Where the countdown started. Defaults to when the script runs; must be before this date.
- pausedAt DateTime | Date | number
Hold the display at the value it had at this moment. Clamped into the interval.
- showsHours Boolean
False shows 90:00 rather than 1:30:00. Default true.
- from DateTime | Date | number
.elapsed(options?)LiveTextTime since this date, counting up live on the Home Screen. Hand the result to Text(). The date must not be in the future; countdown() is for that.
- options Any
- until DateTime | Date | number
Where it stops. Left out, it counts on.
- pausedAt DateTime | Date | number
Hold the display at the value it had at this moment. Clamped into the interval.
- showsHours Boolean
False shows 90:00 rather than 1:30:00. Default true.
- until DateTime | Date | number
.timer()LiveTextCounts down to this date and then up from it, live on the Home Screen: 12:00 before a meeting, 3:45 once it is under way. Hand the result to Text(). No options; for a countdown that stops at zero, or one you can pause, use countdown().
.offset()LiveTextThe signed distance to now, live: "+2 hours" before this date, "-5 minutes" after it. Hand the result to Text(). For a frozen "2 hours ago", use relative().
DateTime.now()DateTime ›Get the current date and time.
DateTime.today()DateTime ›Get today's date at midnight.
DateTime.from(options)DateTime ›Create a date from components: { year, month, day, hour, minute, second }. Also takes a number of epoch seconds, or a JS Date.
- options Any required
Anything left out defaults to the current value for that component.
- year Number
Defaults to the current year.
- month Number
1 to 12.
- day Number
1 to 31.
- hour Number
0 to 23.
- minute Number
0 to 59.
- second Number
0 to 59.
- year Number
Examples
Current date & formatting
const now = DateTime.now();
const formatted = now.format("MMM d, yyyy");
// "Mar 13, 2026"Parsing & comparison
const date = DateTime.parse("2026-01-01");
const today = DateTime.today();
console.log(date.isBefore(today)); // trueDate arithmetic
const tomorrow = DateTime.now()
.add(Duration.days(1));
const diff = tomorrow.difference(DateTime.now());
console.log(diff.inHours); // ~24A countdown that stops at zero
var end = DateTime.now().add(Duration.minutes(25));
Text(end.countdown(), { font: Font.system(40, FontWeight.bold) })A paused timer
// Held at the value it had when it was paused, until the next run.
Text(end.countdown({ from: start, pausedAt: pausedAt }))Time since an event
Text(startedAt.elapsed(), { color: Color.secondaryLabel() })