0

I have an ISO 8601 time string and want to calculate the time difference to now in minutes without using joda time. How is this done?

Thanks

mraviator
  • 4,034
  • 9
  • 38
  • 51

2 Answers2

1

Parse it using SimpleDateFormat to get a Date, get the milliseconds-since-unix-epoch of that using Date.getTime(), then compare with System.currentTimeMillis().

If your ISO-8601 strings contain a time zone offset as something like "-08:00" (which they certainly can), you'll need to remove the colon first, and use the Z format specifier in SimpleDateFormat. (In Java 7 you could use X, but that's not available in Android's version of SimpleDateFormat as far as I'm aware.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

What about javax.xml.datatype.Duration as returned by javax.xml.datatype.DatatypeFactory?

Sofi Software LLC
  • 3,879
  • 1
  • 36
  • 34