DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'"); Date dateGL = null; //得到格林尼治时间 try { dateGL = sdf.parse(data); } catch (ParseException e) { e.printStackTrace(); } TimeZone timeBJ = TimeZone.getTimeZone("PRC"); Calendar c = Calendar.getInstance(); c.setTimeInMillis(dateGL.getTime() + timeBJ.getOffset(dateGL.getTime())); Date dateBJ = c.getTime(); //得到北京时间 DateFormat bj = new SimpleDateFormat("yyyy-MM-dd"); return bj.format(dateBJ); }
java中将type=date的时间转换成北京时间,并返回字符串型
最新推荐文章于 2023-08-18 08:20:35 发布