public class DateUtils {
//日期转换为字符串
public static String dateToString(Date date,String pattern){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String string = simpleDateFormat.format(date);
return string;
}
//日期转换为字符串
public static Date stringToDate(String string,String pattern) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
Date date = simpleDateFormat.parse(string);
return date;
}
public static void main(String[] args) {
Date date = new Date();
System.out.println(dateToString(date,"yyyy-MM-dd"));
}
}
Java日期转换工具类
最新推荐文章于 2024-06-22 11:08:31 发布