Forum Discussion

ilovechiku's avatar
ilovechiku
Contributor
9 years ago

Parsing a date in groovy.

I have a response with a date just like this  BirthDate": "1972-02-12T00:00:00"   i want to get to date like this 02/12/1972   How can i do that?. So far I have tried   def bday =jsonResponse...
  • rupert_anderson's avatar
    9 years ago

    Hi,

     

    Is this what you need?

    Date date = Date.parse("yyyy-MM-dd'T'HH:mm:ss", bday)
    log.info date

    Wed May 11 13:52:49 BST 2016:INFO:Sat Feb 12 00:00:00 GMT 1972

    You can also format it (to a different String format) if need be e.g.

     

    log.info Date.parse("yyyy-MM-dd'T'HH:mm:ss", bday).format('dd/MM/yyyy')

    Wed May 11 13:56:29 BST 2016:INFO:12/02/1972

    Regards,

    Rupert