Unix/Linux Epoch Time Converter.. - Printable Version +- HP Forums (https://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 12:55 AM Simple routine for unix epoch time conversions using hp-41 with time module (or 41CX et al). Useful if you're offline (on a train?) looking at log files.. Be sure to use a constant for reg 00 that is appropriate for your time zone and daylight savings time. (Seconds relative to GMT. Time zone given is Eastern Standard Time.) Initialize constants by running start of program. Uses local labels in user mode. "A" to get current epoch time. Enter: Date [Enter] Time "B" to get epoch time for any given date/time. The "C" routine will translate an epoch time to date/time values. Test in user mode by pressing "A" then "C". This should get you the current date/time. Cheers. Code:
RE: Unix/Linux Epoch Time Converter.. - rprosperi - 12-31-2017 01:54 AM For what machine(s)? Appears to be for a 41, but could be others too... RE: Unix/Linux Epoch Time Converter.. - Bill Duncan - 12-31-2017 02:00 AM Sorry, yes, HP-41 with a time module (or 41cx etc.) The Unix epoch time is the number of seconds past midnight, January 1st, 1970. Unlike real 32bit Unix/Linux (which will have problems in 2038 with signed int being 2^31 seconds), this should be good until the year 2286.. Note that the Time zone info for Register 00 is in seconds relative to GMT. The constant given is Eastern Standard time. RE: Unix/Linux Epoch Time Converter.. - Thomas Okken - 12-31-2017 02:30 AM Should work in Free42 and DM42 as well. Nice post! I have something like this in Free42 at work; very handy when dealing with logs that show raw Unix time stamps, debugging Unix C code, etc. I use it a lot but never thought to post it. RE: Unix/Linux Epoch Time Converter.. - Bill Duncan - 12-31-2017 04:17 PM I've updated. Often all I want is the current epoch time, so I replaced the RTN after the setup into a "SF 27"; so now it falls through into the first routine. More useful I think. Cheers, and Happy New Year. RE: Unix/Linux Epoch Time Converter.. - salvomic - 12-31-2017 04:29 PM (12-31-2017 02:30 AM)Thomas Okken Wrote: Should work in Free42 and DM42 as well. Any help to encode in raw for Free42 (or DM42)? I'm using the SM encoder and I get this error "Invalid instruction ' -18000 STO 00' in line 01". Thank you! Salvo RE: Unix/Linux Epoch Time Converter.. - Sylvain Cote - 12-31-2017 04:36 PM (12-31-2017 04:29 PM)salvomic Wrote:(12-31-2017 02:30 AM)Thomas Okken Wrote: Should work in Free42 and DM42 as well. Look at the line number on the left, he just optimized it for the post Code: 01 LBL "EPOCH" Thank you Bill for this nice routine and Happy New Year! Sylvain RE: Unix/Linux Epoch Time Converter.. - Bill Duncan - 12-31-2017 05:17 PM Yes, sorry Salvo.. I often put several lines of code on one line if I feel that it helps the clarity of the program. Obviously in this case it didn't, or I should've warned everyone anyway.. Cheers. RE: Unix/Linux Epoch Time Converter.. - salvomic - 12-31-2017 06:50 PM (12-31-2017 04:36 PM)Sylvain Cote Wrote: ... (12-31-2017 05:17 PM)Bill Duncan Wrote: Yes, sorry Salvo.. I often put several lines of code on one line if I feel that it helps the clarity of the program. Obviously in this case it didn't, or I should've warned everyone anyway.. Thank you Sylvain and Bill! It worked deleting line numbers, as in this code: Code: LBL "EPOCH" Code: 00 { 94-Byte Prgm } I wonder how to simulate in Free42 the "user mode" (HP41CX) and A, B, C. I'm testing it only executing XEQ "EPOCH" for now... The raw is not good in the emulator i41CX however. Is there a tool to get raw files from text for HP41CX, like the tool by Swiss Micros? Thank you, HNY! Salvo RE: Unix/Linux Epoch Time Converter.. - Bill Duncan - 12-31-2017 07:21 PM 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:
and.. EPOCH-> Code:
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.. Cheers. RE: Unix/Linux Epoch Time Converter.. - grsbanks - 12-31-2017 07:28 PM (12-31-2017 06:50 PM)salvomic Wrote: I wonder how to simulate in Free42 the "user mode" (HP41CX) and A, B, C. That was replaced by the CUSTOM menu. You could alter "EPOCH" so that it not only sets up the constants used but also puts in place a custom menu. RE: Unix/Linux Epoch Time Converter.. - salvomic - 12-31-2017 07:32 PM (12-31-2017 07:28 PM)grsbanks Wrote: That was replaced by the CUSTOM menu. Well, thank you. I'll try it asap. Salvo RE: Unix/Linux Epoch Time Converter.. - Bill Duncan - 01-01-2018 06:26 AM 2017 had a nice round number of 1,500,000,000 epoch seconds back on July 13th.. Happy 2018 everyone.. RE: Unix/Linux Epoch Time Converter.. - salvomic - 01-01-2018 08:24 AM (01-01-2018 06:26 AM)Bill Duncan Wrote: 2017 had a nice round number of 1,500,000,000 epoch seconds back on July 13th.. Indeed... Happy New Year, Buon anno, Bonne et heureuse année! RE: Unix/Linux Epoch Time Converter.. - salvomic - 01-06-2018 06:10 PM Bill, I've put here the version for HP Prime. Enjoy! Salvo RE: Unix/Linux Epoch Time Converter.. - salvomic - 02-09-2018 10:48 PM hi, I've modified the program for DM42 and Free42 (not HP 42s, as it miss the date), adding a custom Menu: [Cur] → Current Epoch time [DT→E] → Date and Time to Epoch [E→DT] → Epoch to Date and Time The program set 3600 as Time Zone variables (Europe, -1), you can set your time/zone (i.e. -18000 as in the original Bill's program). Code:
You can obtain the ".raw" version using the SwissMicros' tool. Enjoy! EDIT 09 Oct 2020: updated code and link to the tool for .raw conversion. |