It is currently April 27th, 2024, 7:36 am

Getting Windows Time from Epoch Time

Get help with creating, editing & fixing problems with skins
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Getting Windows Time from Epoch Time

Post by ZipD »

I have a skin that retrieves an Unix timestamp from a website. I'm trying to convert this to the regular Windows time but it's not showing the time in my timezone (GMT+8):

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,150
AccurateText=1
DynamicWindowSize=1

---------------------------------------------------------------------------------
; MEASURES
---------------------------------------------------------------------------------
[MeasureWorldBoss]
Measure=WebParser
URL=https://www.wowhead.com/diablo-4/event-timers
RegExp=(?siU)<script type="application/json" id="data.d4.worldBosses.status">\{"bossName":"(.*)","spawns":\[\{"pending":.*,"active":(.*),"end"
]
[MeasureWorldBossName]
Measure=WebParser
URL=[MeasureWorldBoss]
StringIndex=1

[MeasureWorldBossSpawnTime]
Measure=WebParser
URL=[MeasureWorldBoss]
StringIndex=2

[MeasureUnixTimeToWindowsTime]
Measure=Calc
; To get a Windows timestamp, which is what Rainmeter uses, you take a unix timestamp and add 11644473600 to it.
Formula=[MeasureWorldBossSpawnTime]+11644473600
DynamicVariables=1

[MeasureTimeConverted]
Measure=Time
TimeStamp=[MeasureUnixTimeToWindowsTime]
Format=%A, %B %#d, %Y %#I:%M %p
DynamicVariables=1

---------------------------------------------------------------------------------
; METERS
---------------------------------------------------------------------------------
[MeterWorldBoss]
Meter=String
MeasureName=MeasureWorldBossName
MeasureName2=MeasureTimeConverted
X=0
Y=0
FontColor=255,255,255
FontSize=15
AntiAlias=1
Text="%1 spawns at %2"
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16175
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Getting Windows Time from Epoch Time

Post by balala »

ZipD wrote: January 14th, 2024, 10:31 pm I have a skin that retrieves an Unix timestamp from a website. I'm trying to convert this to the regular Windows time but it's not showing the time in my timezone (GMT+8):
I'm not home to can give it a try, so am not entirely sure, however here is a start point, I think, but involves a lua script. If you can't deal with this, later when I get home, will try to implement it.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Getting Windows Time from Epoch Time

Post by Yincognito »

Just to clarify, do your measures in the the About > Skins tab correctly get the data and calculate things? Also, is your problem the fact that the Unix time is not displayed at all, or is the fact that it's displayed alright just not adjusted to your timezone?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Re: Getting Windows Time from Epoch Time

Post by ZipD »

It's displayed as intended but not automatically adjusted to my timezone. If I were to correct it manually, I could add 28,800 seconds to it. I just wondered why it would not automatically adjust.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Getting Windows Time from Epoch Time

Post by Yincognito »

ZipD wrote: January 15th, 2024, 1:05 pm It's displayed as intended but not automatically adjusted to my timezone. If I were to correct it manually, I could add 28,800 seconds to it. I just wondered why it would not automatically adjust.
I see. Maybe the note here explains better why automatic adjustment doesn't happen. I believe you'd have to set the TimeZone option in your Time measure to adjust the outcome, but yeah, setting that option is not exactly automatic.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16175
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Getting Windows Time from Epoch Time

Post by balala »

ZipD wrote: January 15th, 2024, 1:05 pm It's displayed as intended but not automatically adjusted to my timezone. If I were to correct it manually, I could add 28,800 seconds to it. I just wondered why it would not automatically adjust.
It seems when a TimeStamp option is defined on a Time measure, the TimeZone option has no effect on the measure. This probably is completely normal, if you defined the time stamp, the time zone doesn't matter anymore.
The solution in my opinion is indeed what you figured out: to add 28800 (8 hours) to the sum calculated by the [MeasureUnixTimeToWindowsTime] measure, by altering its Formula option: Formula=( [MeasureWorldBossSpawnTime:] + 11644473600 + 8 * 3600 ).
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Getting Windows Time from Epoch Time

Post by Yincognito »

ZipD wrote: January 15th, 2024, 1:05 pm It's displayed as intended but not automatically adjusted to my timezone. If I were to correct it manually, I could add 28,800 seconds to it. I just wondered why it would not automatically adjust.
On a second thought, you might want to use a SysInfo measure to get your system timezone automatically (check out the Timezone Values on this page):
https://docs.rainmeter.net/manual/measures/sysinfo/
The value is in minutes though, so you should take that into account when calculating things.

For a more complex case, where the DST for any past, present or future date is also concerned, take look here:
https://forum.rainmeter.net/viewtopic.php?t=39016#p200725
You probably don't need all that, but it illustrates the principle / approach / formulas quite well.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth