/*
* 将String转成Date类型
* 将GMT时间转换成当前时区时间
*/
public static String transform(String from){
String to = "";
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//本地时区
Calendar nowCal = Calendar.getInstance();
TimeZone localZone = nowCal.getTimeZone();
//设定SDF的时区为本地
simple.setTimeZone(localZone);
SimpleDateFormat simple1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置 DateFormat的时间区域为GMT
simple1.setTimeZone(TimeZone.getTimeZone("GMT"));
//把字符串转化为Date对象,然后格式化输出这个Date
Date fromDate = new Date();
try {
//时间string解析成GMT时间
fromDate = simple1.parse(from);
//GMT时间转成当前时区的时间
to = simple.format(fromDate);
} catch (ParseException e1) {
e1.printStackTrace();
}
return to;
}
* 将String转成Date类型
* 将GMT时间转换成当前时区时间
*/
public static String transform(String from){
String to = "";
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//本地时区
Calendar nowCal = Calendar.getInstance();
TimeZone localZone = nowCal.getTimeZone();
//设定SDF的时区为本地
simple.setTimeZone(localZone);
SimpleDateFormat simple1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置 DateFormat的时间区域为GMT
simple1.setTimeZone(TimeZone.getTimeZone("GMT"));
//把字符串转化为Date对象,然后格式化输出这个Date
Date fromDate = new Date();
try {
//时间string解析成GMT时间
fromDate = simple1.parse(from);
//GMT时间转成当前时区的时间
to = simple.format(fromDate);
} catch (ParseException e1) {
e1.printStackTrace();
}
return to;
}