Unix/Linux Epoch Time Converter..

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Unix/Linux Epoch Time Converter.. (/thread-9821.html)



Unix/Linux Epoch Time Converter.. - Bill Duncan - 12-31-2017 01:21 PM

Simple routine for unix epoch time conversions. I thought I'd try my hand in doing an HP-48GX RPL version. Haven't used RPL for awhile, so excuse me if it isn't optimal..

The nice things about the RPL version is that it can test the depth of the stack (so use the current date/time if you haven't entered anything) and, of course it can display the entire date/time string on a single line..

->EPOCH
Code:

<<
  DEPTH IF 2 < THEN
    DATE TIME
  END
  -> D T
  <<
    1.01197 D DDAYS
    86400 *
    T HMS->
    3600 * + 18000 + IP
  >>
>>

and..
EPOCH->
Code:

<<
  18000 - DUP
  86400 / IP 1.01197 SWAP DATE+
  SWAP 86400 MOD
  3600 / ->HMS
  DUP2 TSTR CLLCD
  7 DISP 7 FREEZE
>>

The last routine leaves the date and time in the stack as well as displaying the string.

As in the original version, 18000 is for EST (Eastern Standard Time) and is the number of seconds relative to GMT or UTC. I've put several instructions on a single line for clarity. You should be able to test one against the other by executing "->EPOCH" then translating back with "EPOCH->".

Hope these routines are useful to other unix/linux sysadmins.. Wink
Cheers.