0

I have two strings from an android application in ISO 8601 format that I am trying to find the amount of minutes in between the two times. I was pointed to Joda Time which has been immensely helpful. However I have discovered now that one String is in UTC time and the other is my local time.

For example "2012-05-11T02:34:18+00:00" is UTC and "2012-05-10T21:44:09-05:00" is my local time

I have the following block of code which finds the number of minutes between the two times. My question is how can I go about to change the UTC time to my local time in order to get an accurate minutes in between

DateTime start = new DateTime(currentTime);
DateTime end = new DateTime(laterTime);
int min = Minutes.minutesBetween(start,end).getMinutes();
shyamal
  • 826
  • 10
  • 16

1 Answers1

2

How do I go about to change the UTC time to my local time in order to get an accurate minutes in between?

My understanding is that you don't need to.

A DateTime instance represents a point on the time line, together with a timezone which controls how the time-point is mapped to a time frame (e.g. when you call the getters). When you take a time difference between a pair of DateTime instance, you get a measure representing the duration between two points on the timeline. This is independent of the timezones.

In other words, assuming that the two DateTime instances were created properly, your code should work as-is.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216