It is currently April 26th, 2024, 1:03 am

How to format windows timestamp in order to convert it to Unix?

Get help with creating, editing & fixing problems with skins
User avatar
boozlepuzzle
Posts: 9
Joined: August 22nd, 2021, 9:08 pm
Location: Uruguay

How to format windows timestamp in order to convert it to Unix?

Post by boozlepuzzle »

Hello everyone, I have a weather skin using openweatherAPI which takes Unix timestamp sunrise and sunset times and compares it with the current time in order to find out if it's day or night, like this:

Code: Select all

[MeasureUnix]
Measure=WebParser
URL=https://showcase.api.linx.twenty57.net/UnixTime/tounixtimestamp?datetime=now
RegExp=(?siU)UnixTimeStamp\":\"(.*)\"\}
UpdateRate=300

[MeasureCurrentUnix]
Measure=WebParser
URL=[MeasureUnix]
StringIndex=1
IfCondition=(MeasureSunrise < MeasureCurrentUnix) && (MeasureCurrentUnix < MeasureSunset)
IfTrueAction=[!SetVariable IsDay "1"]
IfFalseAction=[!SetVariable IsDay "0"]
UpdateRate=300
the problem is that the API that tells me the current time has been down for a week, so now my skin doesn't work properly, I thought it would be great if i could use my system time instead of depending on an API, but I'm having trouble formatting Windows timestamp in order to make it just numbers(just seconds since Jan 1st 1601)

if I could do that, then I could convert it to Unix timestamp using this formula I found on the documentation:

Code: Select all

function ConvertTime(n, To)
	local Formats = {
		Unix    = -1
		Windows = 1
		}
	return Formats[To] and n + 11644473600 * Formats[To] or nil
end
Do you know how can I do it? tysm
Last edited by boozlepuzzle on October 2nd, 2022, 8:02 pm, edited 1 time in total.
User avatar
boozlepuzzle
Posts: 9
Joined: August 22nd, 2021, 9:08 pm
Location: Uruguay

Re: How to format windows timestamp in order to convert it to Unix?

Post by boozlepuzzle »

Nevermind, I could get Unix timestamp by using this formula I found on Reddit

Code: Select all

[Hour]
Measure=Time
Format=%I

[Minute]
Measure=Time
Format=%M

[Second]
Measure=Time
Format=%S

[Year]
Measure=Time
Format=%Y

[Day]
Measure=Time
Format=%j

[NumDays]
Measure=Calc
Formula=((Year-1970)*365)+Day+(Floor((Year-1970-1)/4))

[NumSeconds]
Measure=Calc
Formula=((NumDays*86400)+(((Hour*60)+Minute)*60+Second)-17999)+71996
User avatar
SilverAzide
Rainmeter Sage
Posts: 2610
Joined: March 23rd, 2015, 5:26 pm

Re: How to format windows timestamp in order to convert it to Unix?

Post by SilverAzide »

boozlepuzzle wrote: October 2nd, 2022, 8:02 pm Nevermind, I could get Unix timestamp by using this formula I found on Reddit
Wow, there is a lot simpler way than that!

Code: Select all

[MeasureWindowsTimeNow]
Measure=Time

[MeasureUnixTimeNow]
Measure=Calc
Formula=MeasureWindowsTimeNow - 11644473600
IfCondition=(MeasureUnixTimeNow >= MeasureSunrise) && (MeasureUnixTimeNow <= MeasureSunset)
IfTrueAction=[!SetVariable IsDay "1"]
IfFalseAction=[!SetVariable IsDay "0"]
Gadgets Wiki GitHub More Gadgets...
User avatar
boozlepuzzle
Posts: 9
Joined: August 22nd, 2021, 9:08 pm
Location: Uruguay

Re: How to format windows timestamp in order to convert it to Unix?

Post by boozlepuzzle »

SilverAzide wrote: October 2nd, 2022, 8:18 pm Wow, there is a lot simpler way than that!
That's much simpler, thank you so much!