Unix/Linux Epoch Time Converter..
|
12-31-2017, 12:55 AM
(This post was last modified: 12-31-2017 04:13 PM by Bill Duncan.)
Post: #1
|
|||
|
|||
Unix/Linux Epoch Time Converter..
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:
|
|||
12-31-2017, 01:54 AM
Post: #2
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
For what machine(s)?
Appears to be for a 41, but could be others too... --Bob Prosperi |
|||
12-31-2017, 02:00 AM
Post: #3
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. |
|||
12-31-2017, 02:30 AM
Post: #4
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. |
|||
12-31-2017, 04:17 PM
Post: #5
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. |
|||
12-31-2017, 04:29 PM
Post: #6
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
(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 ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
12-31-2017, 04:36 PM
Post: #7
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
(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 |
|||
12-31-2017, 05:17 PM
Post: #8
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. |
|||
12-31-2017, 06:50 PM
(This post was last modified: 12-31-2017 06:56 PM by salvomic.)
Post: #9
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
(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 ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
12-31-2017, 07:21 PM
(This post was last modified: 12-31-2017 07:27 PM by Bill Duncan.)
Post: #10
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. |
|||
12-31-2017, 07:28 PM
Post: #11
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter.. | |||
12-31-2017, 07:32 PM
Post: #12
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
(12-31-2017 07:28 PM)grsbanks Wrote: That was replaced by the CUSTOM menu. Well, thank you. I'll try it asap. Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
01-01-2018, 06:26 AM
Post: #13
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
2017 had a nice round number of 1,500,000,000 epoch seconds back on July 13th..
Happy 2018 everyone.. |
|||
01-01-2018, 08:24 AM
Post: #14
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
(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! ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
01-06-2018, 06:10 PM
Post: #15
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
02-09-2018, 10:48 PM
(This post was last modified: 10-09-2020 04:27 PM by salvomic.)
Post: #16
|
|||
|
|||
RE: Unix/Linux Epoch Time Converter..
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. ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)