java时间格式转换(Sun Oct 22 00:00:00 GMT+08:00 2017)转为("yyyy-MM-dd")
·
System.out.println(time); //Sun Oct 22 00:00:00 GMT+08:00 2017
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.US);
TimeZone tz = TimeZone.getTimeZone("GMT+8");
sdf.setTimeZone(tz);
Date s = null;
String da = null;
Date strToDate = null;
try {
s = sdf.parse(time);
System.out.println(s); // Sun Oct 22 00:00:00 CST 2017
sdf = new SimpleDateFormat("yyyy-MM-dd");
da = sdf.format(s);
System.out.println(da); // 2017-10-22
strToDate = sdf.parse(da);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)