public static void main(String[] args) throws ParseException {
String time = "2019-3-13 9:0:0";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(time);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdf2.format(date);
System.out.println(str);
}
输出结果为:2019-3-13 9:00:00

本文介绍了一个使用Java进行日期时间字符串转换的例子。通过SimpleDateFormat类,将特定格式的字符串转换为Date对象,再将Date对象转换回字符串。示例代码展示了如何处理'2019-3-13 9:0:0'这样的时间格式。
1466

被折叠的 条评论
为什么被折叠?



