Files
javaSE-0113/javaSE-day01/src/com/inmind/date02/DateDemo04.java

47 lines
1.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.date02;
import java.util.Date;
/*
在java中有一个类Date可以表示日期时间的瞬间精确毫秒值
date类的构造方法
Date() 无参构造方法以当前的系统时间来创建出date对象
Date(long date) 有参构造方法根据传入的指定的毫秒值来创建出date对象
指定的毫秒值从1970年1月1日(计算机的基准时间)起,经过的毫秒值
中国处于东八区
Date类的常用方法
long getTime() 返回自1970年1月1日以来date对象所经过的毫秒值。
void setTime(long time) 将此 Date对象设置为1970年1月1日00:00:00起经过的毫秒值
*/
public class DateDemo04 {
public static void main(String[] args) {
//Date() 无参构造方法以当前的系统时间来创建出date对象
Date date = new Date();
//date是引用数据类型保存的是地址
System.out.println(date);//打印对象实际是将该对象的toString方法的内容返回
//Date(long date) 有参构造方法根据传入的指定的毫秒值来创建出date对象
//指定的毫秒值从1970年1月1日(计算机的基准时间)起,经过的毫秒值
//我想要一个1970年1月1日的date对象
Date date1 = new Date(0);
System.out.println(date1);
System.out.println("--------------------常见方法---------------------");
/*
Date类的常用方法
long getTime() 返回自1970年1月1日以来date对象所经过的毫秒值。
void setTime(long time) 将此 Date对象设置为1970年1月1日00:00:00起经过的毫秒值
*/
//获取从1970年1月1到当前时间经过的毫秒值
long time = date.getTime();
System.out.println(time);
//我想要一个1970年1月2日的date对象
date.setTime(24*60*60*1000);
System.out.println(date);
}
}