≡ Menu

Creating Timestamp

Several times I needed a timestamp for whatever reason. Here’s one that will return a scalar containing the current timestamp as in 03Jun19-114251.


sub create_timestamp {
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
    my $month = (qw(Jan Feb Mar Apr May Jun
                    Jul Aug Sep Oct Nov Dec))[$mon];
    $year %= 100;

    my $timestamp = sprintf("%02d%s%02d-%02d%02d%02d",
                         $year, $month, $mday, $hour, $min, $sec);

    return $timestamp;
}
{ 0 comments… add one }

Leave a Comment

Next post:

Previous post: