java格林尼治时间等转成常规日期类型字符串(1)
- UID
- 1066743
|
java格林尼治时间等转成常规日期类型字符串(1)
private Date formatDate(String string) {
SimpleDateFormat resultSdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat resultSdfdate = new SimpleDateFormat("yyyy-MM-dd");
if (string != null) {
if (string.contains("CST")) {
long d2 = Date.parse(string);
Date datetime = new Date(d2);
return datetime;
} else if (string.contains("Z")) {
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd'T'hh:mm:ss'.'sss'Z'");
java.util.Date datetime;
try {
datetime = sdf.parse(string);
return (Date) datetime;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (string.contains("-")&&string.contains(":")) {
Date newDate;
try {
newDate = resultSdf.parse(string);
return newDate;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if(string.contains("-")&&!string.contains(":")){
Date newDate;
try {
newDate = resultSdfdate.parse(string);
return newDate;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
Date longDate = new Date(Long.parseLong(string));
return longDate;
}
}
return null;
} |
|
|
|
|
|