public class TimeTwo {
public static void main(String[] args) throws ParseException{
String s = "2018-08-12 12:02:23";

//使用SimpleDateFormat实现字符串和日期的相互转换
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

System.out.println("转换前的日期:"+s);
//字符串转换数字,parse函数
Date date = sdf2.parse(s);
System.out.println("字符串类型的日期:"+date);
//字符串格式化
String newS = sdf1.format(date);
System.out.println("Date类型的日期:"+newS);
}
}

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-01-18
  • 2021-10-16
  • 2021-11-03
  • 2021-05-10
相关资源
相似解决方案