Perl Human Readable time with miliseconds to EPOCH
I'm parsing SIP messages and we need to include millisecond开发者_StackOverflows in the human readable part (i.e 2011/09/08 00:10:17.997) we need to convert them to Epoch time using Perl, I have found bunch of examples using from Human Readable to Epoch, but not including milliseconds, is this possible? I have found DateTime in CPAN but im having a problem installing it. so looking for other options: Example
$epoch = convert(2011/09/08 00:10:17.997)
print $epoch
and prints: 1315183552
Fix whatever problem it is with your system that is preventing you from installing a module.
Barring that, Epoch time only has second resolution. Strip off the milliseconds and convert using Time::Local (You'll need to parse your SIP message yourself)
$timestamp = "2011/09/08 00:10:17.997";
$timestamp =~ /(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
# ($sec,$min,$hour,$mday,$mon,$year);
$epoch = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
If it's really important, round the second using the milliseconds.
Quick and dirty if you are under linux:
$epoch = `date -d "2011/09/08 00:10:17.997" +%s`; print $epoch;
精彩评论