dateformat - - expected results?

Post your questions and help other users.

Moderator: Martin

Post Reply
DaveyJones
Posts: 1
Joined: 07 Dec 2019 04:06

dateformat - - expected results?

Post by DaveyJones » 14 Dec 2019 06:18

Works
"{selectedDateTime,dateformat,yyyy-MM-dd_HH:mm}" ;

Fails
"{selectedDateTime,dateformat,yyyy-MM-ddTHH:mm}" ;

2019-05-10T13:45 is a sort of standardized format... But the T throws it off...

Expected?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: dateformat - - expected results?

Post by Desmanto » 14 Dec 2019 08:41

Working as expected. T is not the date pattern available. To show a simple char/string inside the format, you have to single quote, 'T'
So the correct one should be.

Code: Select all

select = "{selectedDateTime,dateformat,yyyy-MM-dd'T'HH:mm}" ;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: dateformat - - expected results?

Post by jassing » 14 Dec 2019 18:02

I ran into a similar problem, so I wanted to use a variable to hold the format... Made things worse, since I couldn't do

Code: Select all

{selectedDateTime,dateformat,datefmt}
Last edited by jassing on 15 Dec 2019 03:14, edited 1 time in total.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: dateformat - - expected results?

Post by Desmanto » 14 Dec 2019 19:17

@jassing : You can't put variable inside the dateformat pattern directly. Use eval() and concat the string inside.

Code: Select all

datefmt = "yyyy-MM-dd'T'_HH:mm";
t = eval('"{triggertime,dateformat,' + datefmt + '}"');
You can even decoupled out the time variable part.

Code: Select all

datefmt = "yyyy-MM-dd'T'_HH:mm";
t = eval('"{' + triggertime + ',dateformat,' + datefmt + '}"');
Or even decoupled the format part, but I don't think you have to do that unless you are really get into creating your own custom function.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: dateformat - - expected results?

Post by jassing » 15 Dec 2019 03:13

Neat, I know it won't work... Now. but that would work not in script? For instance writing to a file?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: dateformat - - expected results?

Post by Desmanto » 15 Dec 2019 10:06

You mean eval() + concat method? As long as the final result is what you want, then writing to a file should be correct too. I used to use one of these variable dateformatting before, and then I just make the formatting fixed instead. Better use more script lines than to confuse my future self.

It is just much harder to use eval when you combine too many variable inside. Because you have to take care of the single and double quote, the line separation (if needed) and especially when dealing with regex which can contain so many symbol character.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply