0

I'm sorry if this seems to be a noob question, but I'd really like to know. I have a date (timestamp) which is received from the remote server. Now, according to the developer that date is in UTC.
I'd like to compare that date with the current date on my Android phone considering the difference in timezone.
How can I achieve this? I mean comparing two dates which are both added with the UTC timezone?

MetaSnarf
  • 5,857
  • 3
  • 25
  • 41
  • convert timestamp string to date and get current timestamp from the device , next compare, lot of samples are there .. – Sree Oct 12 '15 at 06:46
  • 1
    TimeZone tz = TimeZone.getTimeZone("Etc/UTC"); Calendar cal = Calendar.getInstance(tz); then you can compare the values. You should just convert the datestamp (possibly a string) to a Calendar instance. If both are calendar, its really easy to compare them – Smashing Oct 12 '15 at 06:48
  • Possible duplicate of [How to compare dates in Java?](http://stackoverflow.com/questions/2592501/how-to-compare-dates-in-java) – Patrick Oct 12 '15 at 08:11
  • wouldn't it matter on what timezone the device is set? – MetaSnarf Oct 12 '15 at 08:45

1 Answers1

0

you can parse string date as Date() object and compare with current date object.

ex.

SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sd.setTimeZone(TimeZone.getTimeZone("UTC"));
Date remoteDate = sd.parse(""); // your utc date
Date localDate = new Date();

then compare them.

M S Parmar
  • 955
  • 8
  • 22