时间类java8
package day20;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Time {
public static void main(String[] args) {
// TODO Auto-generated method stub
LocalDateTime now=LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String format = now.format(formatter);
System.out.println("当前时间为:"+format);
LocalDateTime time=now.plusDays(100);
System.out.println("100天以后的时间为:"+time.format(formatter));
LocalDateTime time1 = LocalDateTime.of(1994, 2, 1, 7, 1, 1);
// 修改当前时间为1994后并返回新对象
LocalDateTime birthday = now.of(1994, 2, 1, 7, 1); // 操作和calendar中的set方法类似
System.out.println("生日:"+birthday.format(formatter));
}
}
java8 时间类
最新推荐文章于 2022-08-10 20:11:53 发布