DateTimeFormatter示例

package date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/**
* java.time.format.DateTimeFormatter 类似于simpleDateFormat
*/
public class DateTimeFormatter1 {
public static void main(String[] args) {
DateTimeFormatter dateTimeFormatter= DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date=dateTimeFormatter.format(LocalDate.now());
System.out.println(date);
TemporalAccessor ld=dateTimeFormatter.parse("2020-03-29");
System.out.println(ld);
}


}
posted @ 2020-03-29 22:43  玄空2  阅读(530)  评论(0编辑  收藏  举报