// 时间转换
public static String transform(String from) {
String to = "";
SimpleDateFormat simple = new SimpleDateFormat("HH:mm:ss");
// 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("HH:mm:ss");
// 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时间
try {
fromDate = simple1.parse(from);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
// GMT时间转成当前时区的时间
to = simple.format(fromDate);
} catch (ParseException e1) {
e1.printStackTrace();
}
return to;
}
安卓开发、ios开发、QT移动开发技术交流学习群 347131054 。欢迎有志做移动开发的同行加入!
347131054347131054
347131054