use POSIX 'strftime'; ## similar to strftime but with milliseconds via "%q" sub sec2date { my ($fmt, $sec) = @_; ## fractional part of $sec, rounded to 3 digits my $milli = sprintf "%03.0f", 1000 * ($sec - int $sec); ## %q becomes our milliseconds $fmt =~ s/%q/$milli/g; strftime $fmt, localtime(int $sec); } #### # convert data2seconds, should be good until the year 2100 #### use Time::Local 'timelocal_nocheck'; ## given year+julian date, my $epoch = timelocal_nocheck $sec, $min, $hour, $julian, 0, $year-1900; ## or given y/m/d (could use normal "timelocal" here) my $epoch = timelocal_nocheck $sec, $min, $hour, $day, $mon-1, $year-1900; ## add milliseconds on at the end: $epoch .= ".$milli"; #### $sec = "0" x (2 - length($time)).$time ; $msec = "0" x (3 - length($msec)).$msec ; #### $sec = sprintf "%02d", $time; $msec = sprintf "%03d", $msec; #### ($format = $format ) =~ s/\%Y/$year/g ; # xxxx ($format = $format ) =~ s/\%m/$month/g ; # 1-12 ($format = $format ) =~ s/\%d/$day/g ; # 01-31 #### for ($format) { s/%Y/$year/g; s/%m/$month/g; ... } #### my %data = ( Y => $year, m => $month, d => $day, ... ); $format =~ s/\%([A-Za-z])/ exists $data{$1} ? $data{$1} : "%$1" /ge;