1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
# ------------------------------------------------
# Fonction getCurrentTimestamp
# -> qui retourne un current timestamp au foramt
# db2
# ex : 2009-10-25 16:35:53.123456
# ------------------------------------------------
sub getCurrentTimestamp
{
my $epochseconds = "0";
my $microseconds = "0";
my $second = "0";
($epochseconds, $microseconds) = Time::HiRes::gettimeofday;
($second, $minute, $hour, $jour, $mois, $annee) = localtime($epochseconds);
$mois += 1 ;
$annee += 1900;
return sprintf("%4d-%2d-%2d %02d:%02d:%02d.%06d", $annee, $mois, $jour, $hour, $minute, $second, $microseconds);
}
# Tests.
$t0 = getCurrentTimestamp();
print "timestamp 0 = [$t0]\n";
$t1 = getCurrentTimestamp();
print "timestamp 1 = [$t1]\n"; |
Partager