It is currently March 28th, 2024, 11:28 am

Using the Uptime measure to format seconds

Our most popular Tips and Tricks from the Rainmeter Team and others
Post Reply
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Using the Uptime measure to format seconds

Post by jsmorley »

While it can be tempting to jump to using a Lua function to convert a number of seconds, perhaps returned by some Time measure, into a formatted string of days, hours, minutes, seconds, there is a way using the Uptime measure native to Rainmeter that can work pretty well with a bit less effort.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureSeconds]
Measure=Calc
Formula=86401

[MesureFormatSeconds]
Measure=UpTime
SecondsValue=[MeasureSeconds]
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

[MeterOutput]
Meter=String
MeasureName=MesureFormatSeconds
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
1.png
Post Reply