I'm using JodaTime
for Android (link) and I'm trying to calculate the Period
between two dates.
One date is from server with Europe/London
timezone and the other date is one I create like :
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/London"));
DateTime now = DateTime.now(dateTimeZone);
What I want is to get the Period
between now and the date I get from the server.
I'm creating a new Period
instance like this :
Period period = new Period(serverDateTime, now, PeriodType.yearMonthDayTime());
but the results I get every time have an offset of 2 hours.
If I print serverDateTime : 2017-02-04T14:30:00.000+02:00
and now
: 2017-02-04T14:30:13.862Z
and for those values I get a period.getHours() == 2
.
What should I change? Both times seem correct but somewhere there's an error
So I was creating the time from server (which I got as a String) like :
and all I have to do was to add the
timezone
, so the answer is :