java8 时间类
時間類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 stubLocalDateTime 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));}}
總結
- 上一篇: MiniDao_1.6-SNAPSHOT
- 下一篇: jeewx 团队微信开发招募新人