Sunday, December 6, 2009

Converting String to Date in Groovy

Recently I was looking for a simple way to convert a String object to a Date format in groovy..
below is the example.

In groovy, its just a one liner to make this happen

String timeStampStr = "2009-12-01T12:36:22Z"
def strDate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss'Z'",timeStampStr)
println strDate.


  1. thank you so much !!!!

  2. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

  3. Is there any way to convert '2017-02-08T02:01:00.000-08:00' string format to the same DateTime format, I do not want to disturb the ordering as I am querying the DB with date time