package demo09;import java.util.Date;public class TestDate {public static void main(String[] args) {//获取当前时间Date now = new Date();//输出当前时间System.out.println(now.toString());System.out.println(now.toLocaleString());System.out.println(now.getYear());System.out.println(now.getMonth());System.out.println(now.getDate());//星期几 星期日是0,一周是从星期日开始System.out.println(now.getDay());System.out.println(now.getHours());System.out.println(now.getMinutes());System.out.println(now.getSeconds());//其他方法long l = now.getTime();//1970年1月1日 00:00:00 GMT以来的毫秒数System.out.println(l);System.out.println(System.currentTimeMillis());System.out.println(System.nanoTime());Date date1 = new Date(-(long)(1000*60*60*24)*31);System.out.println(date1.toLocaleString());}
}
运行结果: