一、返回当前UTC时间
public static String getUTCTimeStr() throws Exception {
Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("GMT");
cal.setTimeZone(tz);
Long mill=cal.getTimeInMillis();
String shijiancuo=String.valueOf(mill);
double shijiancuo2=Double.parseDouble(shijiancuo)/1000;
DecimalFormat df = new DecimalFormat("######0");
return String.valueOf(df.format(shijiancuo2));// 返回的UTC时间戳
}
二、UTC时间第二案例
public static String getUTCTimeStr2() throws Exception {
Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("GMT");
cal.setTimeZone(tz);
return String.valueOf(cal.getTimeInMillis());// 返回的UTC时间戳
}