I want to create a simple countdown timer but currently lost on where to start
It just count the time difference between current time and end time (that I defined)
I am currently looking at this topic but it only shows how to do it when the start time is 0 and end time is something defined in seconds (or vice versa) only https://forum.rainmeter.net/viewtopic.php?p=51733#p51733
It is currently September 8th, 2024, 2:46 am
Simple countdown timer
-
- Posts: 93
- Joined: February 5th, 2017, 4:50 am
Simple countdown timer
deXxterlab97
-
- Rainmeter Sage
- Posts: 16499
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Simple countdown timer
I'll promote again one of my previous works: https://forum.rainmeter.net/viewtopic.php?p=74805#p74805
Probably you need the Countdown skin of this package. Please check it and let me know if it's useful for you.
Probably you need the Countdown skin of this package. Please check it and let me know if it's useful for you.
-
- Posts: 93
- Joined: February 5th, 2017, 4:50 am
Re: Simple countdown timer
Yes it's really useful but your skin only goes up to hourbalala wrote:I'll promote again one of my previous works: https://forum.rainmeter.net/viewtopic.php?p=74805#p74805
Probably you need the Countdown skin of this package. Please check it and let me know if it's useful for you.
I want to create a more detailed countdown that goes up to month and maybe year
I can see a way to make a countdown between 2 dates of a same month but since these 2 are in seperate months it could be a harder task
My approach so far is as follow: make all date to seconds so then I can substract them, then divide the result to get the corresponding result in hours, minutes, seconds...
As for months I am thinking of a conditional statement where it checks what months it is and then return the how many days has past from the start of the year till the beginning of that month, then I have no of days to work with I can then convert them back to seconds. But it looks very long.
This is my code so far
Code: Select all
[Rainmeter]
Update=1000
[Variables]
Month=08
Date=31
Hour=19
Minute=0
Second=0
[CurrentTimeMh]
Measure=Time
Format=%#m
[CurrentTimeD]
Measure=Time
Format=%#d
[CurrentTimeH]
Measure=Time
Format=%#H
[CurrentTimeM]
Measure=Time
Format=%#M
[CurrentTimeS]
Measure=Time
Format=%#S
[HourMinSecDiff] ;in seconds
Measure=Calc
Formula=((#Hour#*3600+#Minute#*60+#Second#)-(CurrentTimeH*3600+CurrentTimeM*60+CurrentTimeS))
[HourDiff]
Measure=Calc
Formula=(FLOOR (HourMinSecDiff / 3600))
[HourTest]
Meter=String
MeasureName=HourDiff
FontColor=255,255,255
deXxterlab97
-
- Developer
- Posts: 22715
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
Brute force math on the month, day, hour, minute, second is never going to work. How many seconds are in a month? How many seconds are in a year? How many seconds are in February? None of those has any reasonable answer that isn't a massive amount of work. You are going to need some function, either in Rainmeter proper or Lua, to convert a date / time string into a timestamp. Then get the current date and time as a timestamp and subtract the two.
Rainmeter has some nice features in the Time measure for turning date / time strings into a Windows timestamp value, and the Uptime measure can actually be used to turn a "difference" in seconds into "days, hours, minutes, seconds".
Rainmeter has some nice features in the Time measure for turning date / time strings into a Windows timestamp value, and the Uptime measure can actually be used to turn a "difference" in seconds into "days, hours, minutes, seconds".
-
- Developer
- Posts: 22715
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
Target=7/26/2017 8:32:10
[MeasureNow]
Measure=Time
Format=%A, %B %#d, %Y %#I:%M %p
[MeasureThen]
Measure=Time
TimeStamp=#Target#
TimeStampFormat=%m/%d/%Y %H:%M:%S
Format=%A, %B %#d, %Y %#I:%M %p
[MeasureDiff]
Measure=Calc
Formula=[MeasureThen:Timestamp]-[MeasureNow:Timestamp]
DynamicVariables=1
IfCondition=MeasureDiff < 1
IfTrueAction=[!SetOption MeterCountdown Text "Target: %1#CRLF#Current: %2#CRLF#Countdown: Completed!"]
IfFalseAction=[!SetOption MeterCountdown Text "Target: %1#CRLF#Current: %2#CRLF#Countdown: %3"]
[MeasureFormatSeconds]
Measure=UpTime
SecondsValue=[MeasureDiff]
Format="%4!i! days %3!i! hours %2!i! minutes %1!i! seconds"
RegExpSubstitute=1
Substitute="^1 days":"1 day"," 1 hours":" 1 hour"," 1 minutes":" 1 minute"," 1 seconds":" 1 second"
DynamicVariables=1
[MeterCountdown]
Meter=String
MeasureName=MeasureThen
MeasureName2=MeasureNow
MeasureName3=MeasureFormatSeconds
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Target: %1#CRLF#Current: %2#CRLF#Countdown: %3
https://docs.rainmeter.net/manual-beta/measures/uptime/
You do not have the required permissions to view the files attached to this post.
-
- Rainmeter Sage
- Posts: 16499
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Simple countdown timer
EDIT: Sorry jsmorley, you again was much quicker then me...
The Countdown.ini of that package counts down from the set time to zero. Have you tried it?deXxterlab97 wrote:Yes it's really useful but your skin only goes up to hour
I think my skin can be easily modified to show not just the hours, minutes and seconds, but the days, months, too.deXxterlab97 wrote:I want to create a more detailed countdown that goes up to month and maybe year
Or for such cases maybe a lua script also could be useful. Lua being a programming language, has functions to get the difference between two moments.deXxterlab97 wrote:I can see a way to make a countdown between 2 dates of a same month but since these 2 are in seperate months it could be a harder task
My approach so far is as follow: make all date to seconds so then I can substract them, then divide the result to get the corresponding result in hours, minutes, seconds...
-
- Developer
- Posts: 22715
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
I actually prefer Lua for this, and almost always use it. Although the timestamp stuff in the Time measure in Rainmeter is perfectly good, I find using the Uptime measure to format the output to be pretty limiting. So I just use Lua for that, and since I'm already out in Lua anyway, I just use the very powerful date / time features in Lua to do the whole thing.balala wrote: Or for such cases maybe a lua script also could be useful. Lua being a programming language, has functions to get the difference between two moments.
-
- Rainmeter Sage
- Posts: 16499
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Simple countdown timer
Yeah, probably it is much more reliable for such calculations. And probably easier to use, at least if the user has some experience.jsmorley wrote:I actually prefer Lua for this, and almost always use it. Although the timestamp stuff in the Time measure in Rainmeter is perfectly good, I find using the Uptime measure to format the output to be pretty limiting. So I just use Lua for that.
-
- Developer
- Posts: 22715
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
While both ways are "reliable" enough, I find it a challenge in Rainmeter to deal with time zones, and Daylight Saving time and "local" vs "UTC" and all that, and Lua is pretty good at it. Not a big deal in this particular case, just counting seconds between two date / time settings that are already "apples and apples", but in other cases, the power of Lua really helps.balala wrote:Yeah, probably it is much more reliable for such calculations. And probably easier to use, at least if the user has some experience.
-
- Developer
- Posts: 22715
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
You will find it difficult to create a countdown that uses years and / or months. The largest time increment that is consistent enough to be accurate is going to be weeks. There are always a fixed number of seconds in a week, day, hour, and minute, but not in a month, year, decade, century etc.deXxterlab97 wrote: I want to create a more detailed countdown that goes up to month and maybe year
To use months or years you are back to just hideous amounts of calculation about "what" month it is, is it a leap year, and all that. That is less a "countdown" type of calculation, and more of a "calendar" calculation.