Date and time strings parsing


#1

Greetings,

1) When using the function [[Now.addDays(-1)]], it returns
Wed May 11 2016 07:07:26 GMT-0500 (CDT)

How can I format the output to show:
May 11, 2016

2) When using the function [[Now.toLocaleTimeString()]] , it returns 7:15:45 AM
How can I format the output to show:
7:15 AM CDT

Thank you for your time and help!
-Ezra


#2

Hi Ezra!

This expression will give you that.

set text on whatever to [[Now.addDays(-1).getMonthName()]] [[Now.addDays(-1).getDate()]], [[Now.addDays(-1).getFullYear()]]

If you want just the first three letters of the month:

set text on whatever to [[Now.addDays(-1).getMonthName().substr(0,3)]] [[Now.addDays(-1).getDate()]], [[Now.addDays(-1).getFullYear()]]

The second one takes an absurd amount of parsing, because you have to convert a string like “Pacific Standard Time” to “PST” - but the following works. It’s easiest with two commands. The first extracts “Pacific Standard Time” or whatever from the result of the keyword Now, and the second converts that string to its acronym and pre-pends the other stuff (removing the seconds from the time). Note: you can find out how all of these string functions work by googling their javascript equivalents. Target.text gives you the existing text of the object whose text you are setting.

set text on whatever to [[Now.substring(Now.indexOf(’(’)+1, Now.indexOf(’)’))]]

set text on whatever to [[Now.toLocaleTimeString().substr(0,Now.toLocaleTimeString().lastIndexOf(’:’))]] [[Now.toLocaleTimeString().slice(-2)]] [[Target.text.substr(0,1)]][[Target.text.substr(Target.text.indexOf(’ ‘)+1,1)]][[Target.text.substr(Target.text.lastIndexOf(’ ')+1,1)]]


#3

Thank you Joseph!


#5

Thanks for this, just what I needed!


closed #6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.