首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java Date 种的创建

2012-11-10 
Java Date 类的创建在日期类中共定义了六种构造函数。?  (1)public Date()  创建的日期类对象的日期时间被

Java Date 类的创建

在日期类中共定义了六种构造函数。

?

  (1)public Date()

  创建的日期类对象的日期时间被设置成创建时刻相对应的日期时间。

  例 Date today=new Date();//today被设置成创建时刻相对应的日期时间。

?

  (2)public Date (long date)

  long 型的参数date可以通过调用Date类中的static方法parse(Strings)来获得。

  例 long l=Date.parse("Mon 6 Jan 199713:3:00");

   ?Date day=new Date(l);

  //day中时间为1997年 1月6号星期一,13:3:00。

?

  (3)public Date(String s)

  按字符串s产生一日期对象。s的格式与方法parse中字符串参数的模式相同。

  例 Date day=new Date("Mon 6 Jan 199713:3:00");

  //day 中时间为1997年1月6号星期一,13:3:00.

?

  (4)public Date(int year,int month,int date)

?

  (5)public Date(int year,int month,intdate,int hrs,int min)

?

  (6)public Date(int year,int month,intdate,int hrs,int min,int sec)

  按给定的参数创建一日期对象。

?

  参数说明:

  year的值为:需设定的年份-1900。例如需设定的年份是1997则year的值应为97,即1997-1900的结果。所以Date中可设定的年份最小为1900;

  month的值域为0~11,0代表1月,11表代表12月;

  date的值域在1~31之间;

  hrs的值域在0~23之间。从午夜到次日凌晨1点间hrs=0,从中午到下午1点间hrs=12;

  min和sec的值域在0~59之间。

热点排行