Java-把日期字符串转换成另一种格式的日期字符串

时间:2023-12-11 10:45:56
package com.example.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; public class DateTimeTrans { public static void main(String[] args) { Date date = new Date();
try {
date = new SimpleDateFormat("HH:mm").parse("13:12:11");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String now = new SimpleDateFormat("HH:mm").format(date);
System.out.println(now);//13:12
}
}