JAVA获取时间,获取指定时区时间
别忘了倒包
指定时区还能解决一些时间不统一等小问题
public class DataTimeUtil {
public static String getCurrentTime(String format)\{ //获取自定义格式的时间
if (format==null || “”.equals(format))
format=”yyyy-MM-dd HHss”;
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone(“Asia/Shanghai”)); //指定时区
return sdf.format(Calendar.getInstance().getTime());
}
public static String getCurrentTime(){ //获取指定格式的时间
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HHss”);
sdf.setTimeZone(TimeZone.getTimeZone(“Asia/Shanghai”)); //指定时区
return sdf.format(Calendar.getInstance().getTime());
}
}
还没有评论,来说两句吧...