2020-04-01T16:54:14.357+0000时间处理转换为yyyy-MM-dd HH:mm:ss

从数据库拿到的数据是2020-04-01T16:54:14.357+0000,页面要显示成yyyy-MM-dd HH:mm:ss格式,先转换成字符串在转换,具体如下

String old_time ="2020-04-01T16:54:14.357+0000";

 DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
 Date date = df.parse(old_time);
 SimpleDateFormat df1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
  Date date1 = df1.parse(date.toString());
  DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  old_time = df2.format(date1);
  Log.e("aaa", "时间" + old_time);

Date转string

Date startday = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String s = df.format(startday);

String转Date

String dateStr = "2020-04-01 17:10:05";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(str);

你可能感兴趣的:(java基础)