【Java】Java中Date和字符串的转换
作者:
Triticale
,
2023-12-31 16:42:04
,
所有人可见
,
阅读 83
Date 与 字符串的转换
package DatePrictice;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;
public class Datetest {
public static void main(String[] args) {
Date d = new Date();
SimpleDateFormat s = new SimpleDateFormat("yyyy:MM:dd:hh:mm:ss");
System.out.println(s.format(d));
String s1 = "2023年12月26日";
SimpleDateFormat s2 = new SimpleDateFormat("yyyy年MM月dd日");
try {
Date date = s2.parse(s1);
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
Date date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd");
String nextDay = simpleDateFormat.format(date);
System.out.println(nextDay);
}
}