Parsing date throws an exception

Hello!

I’m having troubles parsing dates in Ignition scripting.

When I execute the following code:

print(system.date.now())

The output is:

Wed Jun 30 06:28:38 BRT 2021

The problem comes when I try to do the reverse operation, parsing this same string as a Date

date=system.date.parse('Wed May 05 08:11:59 BRT 2021')v

Throws

java.text.ParseException: java.text.ParseException: Unparseable date: "Wed May 05 08:11:59 BRT 2021"

What is causing this? Is it because this date is a ZonedDateTime?

Thanks in advance

you should probably add in the second parameter for the format string

system.date.parse(‘Wed May 05 08:11:59 BRT 2021’, ‘E MMM dd HH:mm:ss z yyyy’ )

image

Yes, I have tried multiple iterations of this parameter:

"EEE MM d kk:mm:ss zzz yyyy"

But nothing seems to be working. Any advice?

I just wrote here above xd

Yeah, it seems like we replied to each other at the same time :slight_smile: . Thank you so much, it worked!

1 Like

np^^ mark my answer as solution if it did^^

1 Like