#-----------------------------------------------------------------------------
#
# Get time string
#
#-----------------------------------------------------------------------------
#
sub formatTime
{
my ( $seconds ) = @_;
my( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime( $seconds );
$year += 1900;
$mon += 1;
return ( sprintf "%02d/%02d/%04d %02d:%02d:%02d",
$mday,$mon,$year,$hour,$min,$sec );
}
#-----------------------------------------------------------------------------
#
# Extract time from the string
#
#-----------------------------------------------------------------------------
#
sub extractTime
{
my ( $edate, $time ) = @_;
my $date = $1 if ($edate =~ /(\d+\/\d+\/\d+)/); # remove leading '[' etc.
my ( $mday, $mon, $year ) = split( /\//, $date );
my ( $hour,$min, $sec ) = split( /:/, $time );
return (timelocal( $sec, $min, $hour, $mday, ($mon - 1), ($year - 1900 )));
}
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
|
||||
|
In order to to get a higher precision for you function Since localtime() only accepts seconds since epoch, you will need to convert the miliseconds passed in and convert it to seconds. Here is an example:
The other option would be to use the DateTime. If you pass in seconds as a decimal, it can create a DateTime object with greater precision:
|
|||
|
formatTime()will need to pass in milliseconds rather than seconds. Also, what have you tried? – jordanm Dec 12 '12 at 2:27