import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateFormatter {
public static void main(String[] args) {
//DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/mm/dd-hh:mm:ss");
//2018/06/15-04:06:13
//DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd-hh:mm:ss");
//2018/10/15-04:06:49
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd-HH:mm:ss");
//2018/10/15-16:07:40
DateTimeFormatter timestampFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
//20181015161416
LocalDateTime now = LocalDateTime.now();
String date = dateTimeFormatter.format(now);
String timestamp = timestampFormatter.format(now);
System.out.println(date);
System.out.println(timestamp);
}
}
So MM
stands for month
, and mm
stands for minute
.
HH
stands for hour in 24-hour clock
, hh
stands for hour in 12-hour clock
.
Generate a timestamp? Pattern yyyyMMddHHmmss
will do.
网友评论