Groovy web console

subscribe to the feed Subscribe
to this
site

Timezone test

Published 1 month ago by tony
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.text.SimpleDateFormat;

String a = "2021-04-06T00:00:00.000-03:00"
String b = "2021-04-06T01:00:00.000-02:00"

String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"

Date aDate = new SimpleDateFormat(dateFormat).parse(a)
Date bDate = new SimpleDateFormat(dateFormat).parse(b)

println "A: ${aDate}"
println "B: ${bDate}"
println "************"

Calendar aCal = Calendar.getInstance()
aCal.setTime(aDate)

Calendar bCal = Calendar.getInstance()
bCal.setTime(bDate)

println aCal.equals(bCal) ? "iguales" : "distintos"