Last active
May 6, 2018 11:40
-
-
Save li2/74208d573a4f8b42d94124628c2b3541 to your computer and use it in GitHub Desktop.
UTC
#tags: java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Date utcDate(String utcTimestamp) { | |
try { | |
String format = "yyyy-MM-dd'T'HH:mm:ss.SSS"; | |
SimpleDateFormat sdf = new SimpleDateFormat(format); | |
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); | |
return sdf.parse(utcTimestamp); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
public long diffToCurrent(String utcTimestamp) { | |
Date date = utcDate(utcTimestamp); | |
if (date != null) { | |
long signalUtcDateMillis = date.getTime(); | |
long currentTimeMillis = System.currentTimeMillis(); | |
return (currentTimeMillis - signalUtcDateMillis); | |
} | |
return 0; | |
} | |
Log.d(TAG, "diff " + diffToCurrent("2018-04-23T05:14:00.000")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment