Formatting time

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Formatting time

Post by MURTUMA » 18 Feb 2015 15:40

I have a random value of milliseconds, for example 105984. How can I format it to HH:mm?

Example value is approx 1,7 minutes, which would convert to 00:02 or 00:01 depending on rounding. Values can be anything below 24 hours.

Rounding isn't an issue here because the value is updated rarely and doesn't need to be exact. But it would be awesome if you could give some tips on that too.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Formatting time

Post by Martin » 18 Feb 2015 20:36

Hi,

You could use {105984,dateformat,timezone,UTC,HH:mm} respectively {variable,dateformat,timezone,UTC,HH:mm}. UTC will ensure that no timezone offset is in use.
The dateformat in this mode behaves like it's rounding down to the minute since it does not show the seconds. You could simulate to round up to the minute by adding 30000ms: {variable+30000,dateformat,timezone,UTC,HH:mm}. Values below 90000ms will still show as 00:01, values above 90000ms will show as 00:02.

Regards,
Martin

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Formatting time

Post by MURTUMA » 19 Feb 2015 03:21

I tried the same earlie but without timezone and utc arguments. It didn't work. Are those required or did I have a typo somewhere?

Anyway, now it works great. Thanks!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Formatting time

Post by Martin » 19 Feb 2015 19:56

It should also work without the timezone and UTC but will give a result that's shifted by the timezone offset currently in use by your device. In my location I would get a result shifted by one hour so {105984,dateformat,HH:mm} shows 01:01.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Formatting time

Post by MURTUMA » 20 Feb 2015 00:19

It must have been a typo then, although I checked it many time that the code is correct. Still, there would have been a problem with timezone, because I wasn't aware of that. I got many problems solved with your answer.

Thanks again!

Post Reply