In DateTime§

See primary documentation in context for method posix.

method posix(Bool:D: $ignore-timezone = False --> Int:D)

Returns the date and time as a POSIX/Unix timestamp (non-leap seconds since the POSIX epoch, 1970-01-01T00:00:00Z).

If $ignore-timezone is True, the DateTime object will be treated as if the time zone offset is zero.

method posix(Bool:D: $ignore-timezone = False, :$real --> Num:D)

Note that this will collapse both a leap second and the second immediately following it into the same timestamp, because POSIX time ignores leap seconds. If you need better than this, see Instant for the relevant methods.

As of release 2022.06 of the Rakudo compiler, it is also possible to specify a :real named argument. If specified with a true value, a Num will be returned, allowing for sub-second accuracy of the number of seconds since the POSIX epoch.

say DateTime.new('2015-12-24T12:23:00Z').posix;           # OUTPUT: «1450959780␤»
say DateTime.new('2022-06-21T12:23:00.5Z').posix;         # OUTPUT: «1655814180␤»
say DateTime.new('2022-06-21T12:23:00.5Z').posix(:real);  # OUTPUT: «1655814180.5␤»