Post Reply 
Epoch (Unix time)
01-06-2018, 09:39 PM (This post was last modified: 01-07-2018 09:35 AM by salvomic.)
Post: #2
RE: Epoch (Unix time)
In this version the user can simply input Date and/or Time and his/her timezone to get current date and time. User can write directly epoc(Date, Time, -5) or input those variables via Vars Catalog.
Otherwise he/she can input a date (format of the Prime: 2018.0106), a time (use the template in shift-E to input i.e. 12°40'32'') and the timezone (timezone is relative to UTC in hours)...

Code:

// Epoch v. 1.1 :: 
// Epoch Unix time from 1970 Jan 1. Inspired by a Bill Duncan's program for HP-41CX
// Thanks to Dieter, Didier Lachieze, Stephen G1CMZ, pier4r...
// Epoch seconds in UTC time
// input: date (e.g. 2018.0523), time (e.g. 13°15'30'')
//     >> or input: Date for current date, and Time for current time (from Var catalog)
// input: timezone (relative to UTC in hours, 0 for GMT/UTC)
EXPORT epoch(dat,tim, zone)
BEGIN
LOCAL sec_in_day:=24*60*60; //86400
LOCAL sec_in_hour:=60*60; //3600
LOCAL unix_epoch_start_time:=1970.0101;
IF tim<>Time THEN tim:=HMS→(tim); END;
tim:=tim-zone;
RETURN sec_in_day*(DDAYS(unix_epoch_start_time,dat))+sec_in_hour*HMS→(tim);
END;

// Given an epoch and a time zone, the program returns date and time
// Input: epoch in seconds, timezone (0 for GMT / UTC) 
EXPORT epoch2date(epoc, zone)
BEGIN
LOCAL sec_in_day:=24*60*60; //86400
LOCAL sec_in_hour:=60*60; //3600
LOCAL unix_epoch_start_time:=1970.0101;
LOCAL dat, tim;
epoc:=epoc+sec_in_hour*zone;
dat:=DATEADD(unix_epoch_start_time, IP(epoc/sec_in_day));
tim:=(epoc MOD sec_in_day)/sec_in_hour;
RETURN({dat, →HMS(tim)});
END;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Epoch (Unix time) - salvomic - 01-06-2018, 06:07 PM
RE: Epoch (Unix time) - salvomic - 01-06-2018 09:39 PM



User(s) browsing this thread: 1 Guest(s)