- /**
- * Description: 获取GMT8时间
- * @return 将当前时间转换为GMT8时区后的Date
- */
- public static Date getGMT8Time(){
- Date gmt8 = null;
- try {
- Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE);
- Calendar day = Calendar.getInstance();
- day.set(Calendar.YEAR, cal.get(Calendar.YEAR));
- day.set(Calendar.MONTH, cal.get(Calendar.MONTH));
- day.set(Calendar.DATE, cal.get(Calendar.DATE));
- day.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY));
- day.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
- day.set(Calendar.SECOND, cal.get(Calendar.SECOND));
- gmt8 = day.getTime();
- } catch (Exception e) {
- System.out.println("获取GMT8时间 getGMT8Time() error !");
- e.printStackTrace();
- gmt8 = null;
- }
- return gmt8;
- }
Java获取GMT8时间
最新推荐文章于 2024-08-29 03:46:38 发布