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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Parse it using
SimpleDateFormatto get aDate, get the milliseconds-since-unix-epoch of that usingDate.getTime(), then compare withSystem.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
Zformat specifier inSimpleDateFormat. (In Java 7 you could useX, but that’s not available in Android’s version ofSimpleDateFormatas far as I’m aware.)