Search code examples
perltimestampjulian-date

18 digit julian timestamp in perl


I need to get 18-digit Julian Timestamp in my perl script. Could anyone help me in this? However I have written a subroutine to achieve this but it does not look good to me since it always gives me a number ending with 6 zeroes. Please help to get a proper 18-digit J-timestamp.

sub GetJulianTimestamp()
{
  my $t = `perl -e 'print time, "\n"'`;
  return (($t * 1000000 ) + 210866803200000000);
}

Solution

  • Based on the comments, you appear to be asking how to obtain the number of microseconds since the unix epoch.

    use Time::HiRes qw( );
    
    my $microsec_time = int( Time::HiRes::time() * 1_000_000 );
    return 210866803200000000 + $microsec_time;