*9.3(使用Date类)编写程序创建一个 Date 对象,设置它的流逝时间分别为 10000、100000、1000000、10000000、100000000、1000000000、10000000000、100000000000 ,然后使用 toString() 方法分别显示上述日期。 *9.3(Using the date class)Write a program to create a date object, set its elapse time to 10000, 100000, 1000000, 100000000, 1000000000, 1000000000, 1000000000, 10000000000, and then use tostring() method to display the above dates respectively.
参考代码:
package chapter09;import java.util.Date;publicclassCode_03{
publicstaticvoidmain(String[] args){
for(long l =10000,i =0;i <8;i++){
Date date =newDate(l);toString(l,date);
l *=10;}}publicstaticvoidtoString(long l, Date date){
System.out.println(l +": "+ date.toString());}}
结果显示:
10000: Thu Jan 0108:00:10 CST 1970100000: Thu Jan 0108:01:40 CST 19701000000: Thu Jan 0108:16:40 CST 197010000000: Thu Jan 0110:46:40 CST 1970100000000: Fri Jan 0211:46:40 CST 19701000000000: Mon Jan 1221:46:40 CST 197010000000000: Mon Apr 2701:46:40 CST 1970100000000000: Sat Mar 0317:46:40 CST 1973
Process finished with exit code 0