How to get 'milliseconds' as a part of time in perl? -


this question has answer here:

i need time in format "20130808 12:12:12.123" i.e., "yyyymmdd hour:min:sec.msec".

i tried

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);  $year += 1900; $mon++; if ($mon<10){$mon="0$mon"}  if ($mday<10){$mday="0$mday"}  if ($hour<10){$hour="0$hour"}  if ($min<10){$min="0$min"}  if ($sec<10){$sec="0$sec"}  doesn't provide `msec` part of time. 

how can ?

here's complete script. proposed before, using time::hires::time microsecond support, , it's using posix::strftime easier formatting. unfortunately strftime cannot deal microseconds, has added manually.

use time::hires qw(time); use posix qw(strftime);  $t = time; $date = strftime "%y%m%d %h:%m:%s", localtime $t; $date .= sprintf ".%03d", ($t-int($t))*1000; # without rounding  print $date, "\n"; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -