Created
October 13, 2014 05:15
-
-
Save smallnewer/8487f11848abe00d7427 to your computer and use it in GitHub Desktop.
解析ISO时间格式
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
/** | |
* 解析ISO时间 | |
* | |
* 如果是两天内,格式为:“今天 08:08”"昨天 16:18" | |
* 如果是两天前,格式为:"月-日" | |
* | |
*/ | |
public String ISOTimeFormat(String isotime) { | |
java.text.DateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'"); | |
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); | |
Date t = null; | |
try { | |
t = sdf.parse(isotime); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
if (t == null) { | |
return null; | |
} | |
Calendar target = Calendar.getInstance(); | |
target.setTime(t); | |
Calendar now = Calendar.getInstance(); | |
int intervalMon = now.get(Calendar.MONTH) - target.get(Calendar.MONTH); | |
int intervalDay = now.get(Calendar.DAY_OF_MONTH) - target.get(Calendar.DAY_OF_MONTH); | |
if (intervalMon == 0 && intervalDay <= 1) { | |
if (intervalDay == 0) { | |
return "今天 " + target.get(Calendar.HOUR_OF_DAY) + ":" + target.get(Calendar.MINUTE); | |
} | |
if (intervalDay == 1) { | |
return "昨天 "+ target.get(Calendar.HOUR_OF_DAY) + ":" + target.get(Calendar.MINUTE); | |
} | |
} | |
java.text.DateFormat ret = new java.text.SimpleDateFormat("MM-dd"); | |
return ret.format(target.getTime()); | |
} |
你在做镜像文件???
没有~~
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
学习了