Java之格林威治時間格式轉換成北京時間格式
package com.mtons.mblog;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class DateUtils {
public static String getTimestampTimeV16(String str) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
sdf.setTimeZone(tz);
Date date = sdf.parse(str);
String string = date.toString();
return string;
}
public static String getTimestampTimeV17(String str) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
Date date = sdf.parse(str);
String string = date.toString();
return string;
}
public static String getTimeToDay(String str){
Date date = new Date(1464166640L*1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(date);
}
}