下面的程序中,请问将time定义为-1000L的意思,与time定义为1000L有什么不同import java.util.Date;
import java.text.SimpleDateFormat;
public class Example7_1{
public static void main(String args[]){
SimpleDateFormat matter1=new SimpleDateFormat("北京时间yyyy-MM-dd HH:mm:ss(a)(EE)");
long time=-1000L;
Date date=new Date(time);
System.out.println(time+"日期是: "+matter1.format(date));
time=1000L;
date =new Date(time);
System.out.println(time+"日期是: "+matter1.format(date));
}
}
import java.text.SimpleDateFormat;
public class Example7_1{
public static void main(String args[]){
SimpleDateFormat matter1=new SimpleDateFormat("北京时间yyyy-MM-dd HH:mm:ss(a)(EE)");
long time=-1000L;
Date date=new Date(time);
System.out.println(time+"日期是: "+matter1.format(date));
time=1000L;
date =new Date(time);
System.out.println(time+"日期是: "+matter1.format(date));
}
}
传-1000则表示在1970-01-01 08:00:00这个时间的后面(离现在远),即减一秒,1970-01-01 07:59:59
传入1000则表示在1970-01-01 08:00:00这个时间的前面面(里现在近),即加一秒1970-01-01 08:00:01
查看jdk帮助文档会发现------以表示自从标准基准时间(称为“历元(epoch)”,即 1970 年 1 月 1 日 00:00:00 GMT)以来的指定毫秒数。 这个时间转换为北京时间即为:1970-01-01 08:00:00