Unix Timestamp in Perl

Built-in `time()` for current epoch; use `DateTime` from CPAN for richer manipulation.

Common Operations

Get current Unix timestamp

my $ts = time();
# 1706745600

Convert Unix timestamp to date string

my @t = gmtime(1706745600);
printf "%04d-%02d-%02d %02d:%02d:%02d UTC\n",
  $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0];

Format as ISO 8601 (DateTime)

use DateTime;
my $dt = DateTime->from_epoch(epoch => 1706745600);
print $dt->iso8601 . 'Z';

Other Languages

Need the full converter? Open the Timestamp Converter →