0

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);
}
paper.plane
  • 1,201
  • 10
  • 17
  • 1
    `210866803200000000` is the Julian timestamp for the UNIX epoch to add more context. – Hunter McMillen Apr 06 '15 at 14:32
  • 1
    You're multiplying an integer by 1000000 and wondering why you're getting all zeros in the right 6 places? Have you tried to `use Time::HiRes` and avoid shelling out? – tjd Apr 06 '15 at 14:41
  • Yah, the zeroes are pretty much obvious, that's what I mentioned, "it does not look good to me" – paper.plane Apr 06 '15 at 14:43
  • Wondering why you ran a separate instance Perl to get `$t`, rather than just running `my $t = time`. – Dave Cross Apr 10 '15 at 12:47

2 Answers2

6

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;
ikegami
  • 367,544
  • 15
  • 269
  • 518
0

I agree with the answer given by ikegami, except the amount to be added to the unix epoch needs to be changed. The value 210866803200000000 corresponds to November 24, 4714 BC, 00:00 Universal Time, Gregorian proleptic calendar. But the epoch of Julian dates is at noon, not midnight. So the amount to be added should be 210,866,760,000,000,000. And of course there is no official name for a Julian date that has been converted to microseconds, so anyone using such a number would have to provide an explanation to anyone who is receiving the data.

Gerard Ashton
  • 560
  • 4
  • 16