Parsing Timestamp

I'm trying to parse a timestamp in a JSON parser, but I'm not having any luck despite trying various things in the dev guide.

Format:  "2022-05-16 19:54:25 +0000 UTC"

My token:
token[2].name=backend_timestamp
token[2].type=String
token[2].location=backend_timestamp

Here are the various things I've tried.  On the regexToken, I was trying to strip off the timezones, but failed lol.
event.deviceCustomDate1=__safeToDate(__regexToken(backend_timestamp,"(\\d+\\-\\d+\\-\\d+\\s\\d\\d:\\d\\d:\\d\\d).*"),"yyyy-MM-dd HH:mm:ss"))
event.deviceCustomDate1=__safeToDate(backend_timestamp,"yyyy-MM-dd HH:mm:ss.SSSSSSS ZZZZZ zzz")
event.deviceCustomDate1==__parseMultipleTimeStamp(backend_timestamp,"yyyy-MMM-dd HH:mm:ss.SSSSSSS ZZZZZ zzz","yyyy-MMM-dd HH:mm:ss:SSSSSSS ZZZZZ zzz")

Any suggestions on what might work?

Thanks!

  • Hi Jklein

    event.deviceCustomDate1==__parseMultipleTimeStamp(backend_timestamp,"yyyy-MMM-dd HH:mm:ss.SSSSSSS ZZZZZ zzz","yyyy-MMM-dd HH:mm:ss:SSSSSSS ZZZZZ zzz")

    there are no millis in your sample... 

    Not sure why this is not working:

    event.deviceCustomDate1=__safeToDate(__regexToken(backend_timestamp,"(\\d+\\-\\d+\\-\\d+\\s\\d\\d:\\d\\d:\\d\\d).*"),"yyyy-MM-dd HH:mm:ss"))


    Also i would suggest it to put it into a String field, so you see the result.

    Did you try the regex tool? 

    you also should have access to the unob Parser, they are a tresure for you ;)

    KR

    A

  • Hi Vitz,

    Sorry, I copied the wrong sample & have another sample that has the milliseconds.

    Thanks for your suggestions, really helpful.  I realized I just had an extra ")" at the end!  lol
    Removing that ") at the end fixed it.

    That said, I didn't really want to remove the time zone if I didn't need to.  I opened a ticket and they suggested using the __concatenate function. 
    Basically stripping off the "+0000 UTC" through regex, then adding "UTC" back on at the end.

    "2022-05-16 19:54:25 +0000 UTC"
    event.deviceCustomDate1=__safeToDate(__concatenate(__regexToken(backend_timestamp,"(\\d+\\-\\d+\\-\\d+\\s\\d\\d:\\d\\d:\\d\\d).*),UTC"),"yyyy-MM-dd HH:mm:ss zzz")

    That should work of for the millisecond sample too.
    There's probably a way to tokenize the time zone with another regex expression, but this should work fine for me because the time zone is always UTC in these logs.