Epoch time using Python vs MS

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury, Rain

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 351
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Epoch time using Python vs MS

Post by Grovkillen » Thu Jan 17, 2019 1:26 pm

Code: Select all

/*
python_epoch_time:
import time
print(time.time())
*/

LabelToVar>python_epoch_time,pcode_python_epoch_time
PYExec>pcode_python_epoch_time,epoch_time
MDL>epoch_time
Other fancy stuff you can do: https://docs.python.org/3/library/time.html#module-time

This one might be helpful.

Code: Select all

/*
python_timezone:
import time
print(time.timezone)
*/

LabelToVar>python_timezone,pcode_timezone
PYExec>pcode_timezone,timezone
MDL>%timezone% in minutes
Last edited by Grovkillen on Thu Jan 31, 2019 11:00 am, edited 1 time in total.
Let>ME=%Script%

Running: MS14.5.4

User avatar
Grovkillen
Automation Wizard
Posts: 351
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Epoch time using Python vs MS

Post by Grovkillen » Wed Jan 30, 2019 5:25 pm

Here's a MS version of the same:

Code: Select all

//Set your time zone offset from UTC in minutes
Let>MY_TIME_ZONE=60

Label>START
GetDate>DATE_NOW
DateDiff>DATE_NOW,1970-01-01,D,EPOCH_D
Let>EPOCH_D=EPOCH_D*86400
GetTime>TIME_NOW
TimeDiff>TIME_NOW,00:00:01,S,EPOCH_T
Let>EPOCH_NOW={%EPOCH_D%+%EPOCH_T%-%MY_TIME_ZONE%*60}
Message>EPOCH_NOW
GoTo>START
Let>ME=%Script%

Running: MS14.5.4

User avatar
Grovkillen
Automation Wizard
Posts: 351
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Epoch time using Python vs MS

Post by Grovkillen » Wed Jan 30, 2019 5:45 pm

EPOCH 2 Date:

Code: Select all

Let>EPOCH_TIME=1548869385

GoSub>EPOCH_2_DATE,%EPOCH_TIME%,60

MDL>REAL_DATE

SRT>EPOCH_2_DATE
  //S in a D
  Let>TEMP={%EPOCH_2_DATE_Var_1%/86400}
  Separate>TEMP,%DECIMAL_SEPARATOR%,TEMP
  Let>EPOCH_DAYS=%TEMP_1%
  //Remove D from EPOCH
  Let>EPOCH_SECONDS={%EPOCH_2_DATE_Var_1%-%EPOCH_DAYS%*86400}
  DateLocal>1970,01,01,EPOCH_START
  DateAdd>EPOCH_START,D,EPOCH_DAYS,DATE
  //Add timezone to remaining S
  Let>EPOCH_SECONDS={%EPOCH_SECONDS%+%EPOCH_2_DATE_Var_2%*60}
  //Seconds PASSED since 1970-01-01 00:00:00... we need to add one second
  TimeAdd>00:00:01,S,EPOCH_SECONDS,TIME
  //Make readable
  Let>REAL_DATE=%DATE% %TIME%
END>EPOCH_2_DATE
Let>ME=%Script%

Running: MS14.5.4

User avatar
Grovkillen
Automation Wizard
Posts: 351
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Epoch time using Python vs MS

Post by Grovkillen » Mon Jun 10, 2019 1:15 pm

I have found a way of determing the daylight and timezone using the registry:

Code: Select all

RegistryReadKey>HKEY_LOCAL_MACHINE,SYSTEM\CurrentControlSet\Control\TimeZoneInformation,Bias,BIASED_TIME_ZONE
RegistryReadKey>HKEY_LOCAL_MACHINE,SYSTEM\CurrentControlSet\Control\TimeZoneInformation,StandardBias,BIASED_DST_ADD
Let>MY_OFFSET_FROM_UTC=BIASED_TIME_ZONE+BIASED_DST_ADD
Label>START
Timer>RUN_TIMER
If>RUN_TIMER>10000
  Exit>0
Endif>
GetDate>DATE_NOW
DateDiff>DATE_NOW,1970-01-01,D,EPOCH_D
Let>EPOCH_D=EPOCH_D*86400
GetTime>TIME_NOW
TimeDiff>TIME_NOW,00:00:01,S,EPOCH_T
Let>EPOCH_NOW={%EPOCH_D%+%EPOCH_T%+%MY_OFFSET_FROM_UTC%*60}
Message>EPOCH_NOW
GoTo>START
Let>ME=%Script%

Running: MS14.5.4

Post Reply