It is currently April 19th, 2024, 7:23 pm

Convert time string to 12h format

Get help with creating, editing & fixing problems with skins
User avatar
xenium
Posts: 865
Joined: January 4th, 2018, 9:52 pm

Convert time string to 12h format

Post by xenium »

Hi,
How can I convert the time string to 12h format ?
Like this (without leading zeros):

"00:43" - "12:43 am"
"02:17" - "2:17 am"
"17:23" - "5:23 pm"

Thanks
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert time string to 12h format

Post by jsmorley »

xenium wrote: November 22nd, 2019, 11:28 am Hi,
How can I convert the time string to 12h format ?
Like this (without leading zeros):

"00:43" - "12:43 am"
"02:17" - "2:17 am"
"17:23" - "5:23 pm"

Thanks
Can you show me the measure that is getting the time to begin with? That matters... It's really, really hard to plot a course to a destination if you don't know where you are starting from!

Code: Select all

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

[Variables]

[MeasureTime24]
Measure=String
String=17:51

[MeasureTime12]
Measure=Time
DynamicVariables=1
TimeStamp=[MeasureTime24]
TimeStampFormat=%H:%S
Format=%#I:%S %p

[MeterTime]
Meter=String
MeasureName=MeasureTime12
FontSize=25
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
StringCase=Lower
AntiAlias=1

1.png



https://docs.rainmeter.net/manual/measures/time/#TimeStamp
https://docs.rainmeter.net/manual/measures/time/#TimeStampFormat
https://docs.rainmeter.net/manual/measures/time/#FormatCodes
You do not have the required permissions to view the files attached to this post.
User avatar
xenium
Posts: 865
Joined: January 4th, 2018, 9:52 pm

Re: Convert time string to 12h format

Post by xenium »

jsmorley wrote: November 22nd, 2019, 1:37 pm Can you show me the measure that is getting the time to begin with? That matters...

Code: Select all

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

[Variables]

[MeasureTime24]
Measure=String
String=17:51

[MeasureTime12]
Measure=Time
DynamicVariables=1
TimeStamp=[MeasureTime24]
TimeStampFormat=%H:%S
Format=%#I:%S %p

[MeterTime]
Meter=String
MeasureName=MeasureTime12
FontSize=25
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
StringCase=Lower
AntiAlias=1


1.png




https://docs.rainmeter.net/manual/measures/time/#TimeStamp
https://docs.rainmeter.net/manual/measures/time/#TimeStampFormat
https://docs.rainmeter.net/manual/measures/time/#FormatCodes
Thank you very much !
It works! :bow:
jsmorley wrote: November 22nd, 2019, 1:37 pm Can you show me the measure that is getting the time to begin with? That matters...
This is the measure:

Code: Select all

[MeasureSunrise]
Measure=WebParser
Url=[MeasureSun]
StringIndex=1
RegExpSubstitute=1
Substitute="^.*T(.*):.*$":"\1"
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert time string to 12h format

Post by jsmorley »

xenium wrote: November 22nd, 2019, 2:04 pm Thank you very much !
It works! :bow:


This is the measure:

Code: Select all

[MeasureSunrise]
Measure=WebParser
Url=[MeasureSun]
StringIndex=1
RegExpSubstitute=1
Substitute="^.*T(.*):.*$":"\1"
Yes, in this case my solution should be the right one. Glad to help.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Convert time string to 12h format

Post by SilverAzide »

jsmorley wrote: November 22nd, 2019, 1:37 pmIt's really, really hard to plot a course to a destination if you don't know where you are starting from!
Another Morley classic! That's a keeper... :D
Gadgets Wiki GitHub More Gadgets...