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,004
  • 8
  • 37
  • 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,335,956
  • 823
  • 8,931
  • 9,049
0

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

Sofi Software LLC
  • 3,606
  • 1
  • 32
  • 33