第九章第三题(使用Date类)(Using the date class)

第九章第三题(使用Date类)(Using the date class)

  • *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;

public class Code_03 {
    
    
    public static void main(String[] args) {
    
    
        for (long l = 10000,i = 0;i < 8;i++){
    
    
            Date date = new Date(l);
            toString(l,date);
            l *= 10;
        }
    }
    public static void toString(long l, Date date){
    
    
        System.out.println(l + ": " + date.toString());
    }
}

  • 结果显示:
10000: Thu Jan 01 08:00:10 CST 1970
100000: Thu Jan 01 08:01:40 CST 1970
1000000: Thu Jan 01 08:16:40 CST 1970
10000000: Thu Jan 01 10:46:40 CST 1970
100000000: Fri Jan 02 11:46:40 CST 1970
1000000000: Mon Jan 12 21:46:40 CST 1970
10000000000: Mon Apr 27 01:46:40 CST 1970
100000000000: Sat Mar 03 17:46:40 CST 1973

Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/jxh1025_/article/details/109256900