2021-04-21

AutoHotkey & Java: Calendar will take your given milliseconds as UTC, then offset with your timezone when you do: Calendar.getTime().

 
Senarior:
Come across to integrate AutoHotkey & Java.

getting timestamp in milliseconds from AutoHotkey, then pass into Java process.


Found out:
Calendar will offset your milliseconds(a or b, which is UTC timstamp) with your timezone.


Given as below:

a = Calendar.getTime()

&

b = System.currentTimeMillis()

&

EpochTimestamp_Now_UTC := A_NowUTC
EnvSub, EpochTimestamp_Now_UTC, 19700101000000, Seconds
Milliseconds_Now_UTC := EpochTimestamp_Now_UTC * 1000 + A_MSec
c := Milliseconds_Now_UTC 


Billson@20210415_pm121738 : System.currentTimeMillis(); = Calendar.getInstance().getTimeInMillis(); = A_NowUTC in EpochTimestamp = EpochTimestamp_Now_UTC

Three above(a, b, c) are identical, and they will hold UTC timestamp.

BUT

When u pass back into
Calendar calTmp = Calendar.getInstance();
calTmp.setTimeInMillis(milliseconds);

Sysout#1
calTmp.setTimeInMillis(a);
System.out.println(calTmp.getTime());

Sysout#2
calTmp.setTimeInMillis(c);
System.out.println(calTmp.getTime());

Sysout#1 & Sysout#2 will show your localtime.

Calendar will offset your milliseconds(a or b, which is UTC timstamp) with your timezone.
But not sure happen this offset within which part.










No comments:

Google Referrals