Course of Raku / Advanced / More about built-in types / Date and time
Working with time
When you need the time of day as well as the date, use the
DateTime type. It is created much like a Date,
but you also give the hour, minute, and second:
my $dt = DateTime.new(2026, 6, 27, 14, 30, 0);
say $dt; # 2026-06-27T14:30:00ZThe default text form follows the ISO 8601 standard: the date, the
letter T, the time, and a trailing Z for the
UTC time zone.
A DateTime gives access to the time parts, in addition
to the date parts you already know:
my $dt = DateTime.new(2026, 6, 27, 14, 30, 0);
say $dt.hour; # 14
say $dt.minute; # 30To get the current moment, call DateTime.now. As with
Date.today, we do not show its output, because it changes
every time the program runs.
Course navigation
← Quiz — Adding months | Weeks until Christmas →
💪 Or jump directly to the exercises in this
section.