JAVA实现GMT转换北京时间

简单粗暴上代码,把获取到http的响应头的GMT时间转换成北京时间

		String urlStr = "http://aaa.bbb.cc/a.pdf";
        Set headSet = new HashSet<>();
        headSet.add("Last-Modified");
        Map resultMap = HttpUtil.doGetHttpResponceHeader(urlStr, headSet);
        System.out.println("resultMap值=" + resultMap + "," + "当前类=HttpUtil.main()");
        String gmtTime = resultMap.get("Last-Modified").toString();
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        Date date = dateFormat.parse(gmtTime);
        System.out.println("date=" + date + "," + "当前类=HttpUtil.main()");
		
		//加8个时区
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
        date = calendar.getTime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatTime = sdf.format(date);
        System.out.println("formatTime=" + formatTime + "," + "当前类=HttpUtil.main()");

你可能感兴趣的:(java,GMT,GMT转化北京时间)