ºìÁªLinuxÃÅ»§
Linux°ïÖú

JAVA»ù´¡£º½÷É÷ʹÓÃDateºÍTimeÀà

·¢²¼Ê±¼ä:2006-10-14 00:55:39À´Ô´:ºìÁª×÷Õß:ckernel
AVAÀïÌṩµÄÈÕÆÚºÍʱ¼äÀ࣬java.sql.DateºÍjava.sql.Time,Ö»»á´ÓÊý¾Ý¿âÀï¶Áȡij²¿·ÖÖµ£¬ÕâÓÐʱ»áµ¼Ö¶ªÊ§Êý¾Ý¡£ÀýÈçÒ»¸ö°üº¬2002/05/22 5:00:57 PMµÄ×ֶΣ¬¶ÁÈ¡ÈÕÆÚʱµÃµ½µÄÊÇ2002/05/22,¶ø¶Áȡʱ¼äʱµÃµ½µÄÊÇ5:00:57 PM.


ÄãÐèÒªÁ˽âÊý¾Ý¿âÀï´æ´¢Ê±¼äµÄ¾«¶È¡£ÓÐЩÊý¾Ý¿â£¬±ÈÈçMySQL,¾«¶ÈΪºÁÃ룬Ȼ¶øÁíһЩÊý¾Ý¿â£¬°üÀ¨Oracle,´æ´¢SQL DATEÀàÐÍÊý¾Ýʱ£¬ºÁÃ벿·ÖµÄÊý¾ÝÊDz»±£´æµÄ¡£ÒÔϲÙ×÷ÖÐÈÝÒ׳öÏÖ²»Ò×±»·¢ÏÖµÄBUG£º

»ñµÃÒ»¸öJAVAÀïµÄÈÕÆÚ¶ÔÏó¡£
´ÓÊý¾Ý¿âÀï¶ÁÈ¡ÈÕÆÚ
ÊÔͼ±È½ÏÁ½¸öÈÕÆÚ¶ÔÏóÊÇ·ñÏàµÈ¡£Èç¹ûºÁÃ벿·Ö¶ªÊ§£¬±¾À´ÈÏΪÏàµÈµÄÁ½¸öÈÕÆÚ¶ÔÏóÓÃEquals·½·¨¿ÉÄÜ·µ»Øfalse¡£
java.sql.TimestampÀà±Èjava.util.DateÀྫȷ¶ÈÒª¸ß¡£Õâ¸öÀà°üº¬ÁËÒ»¸ögetTime()·½·¨£¬µ«ÊÇËü²»»á·µ»Ø¶îÍ⾫¶È²¿·ÖµÄÊý¾Ý£¬Òò´Ë±ØÐëʹÓÃgetNanos()·½·¨¡£ÓкÁ΢Ã벿·Ö£¨¼´¶îÍ⾫¶È²¿·Ö£©µÄÊýÖµ¿ÉÄܱÈûÓÐÕâ¸ö²¿·ÖµÄÊýÖµµÄ´óÒ»¸öºÁÃë¡£Èç¹ûÄãÖªµÀÄãʹÓõÄÊý¾Ý¿â±£´æÁ˺ÁÃ벿·Ö£¬¿ÉÒÔÓÃÏÂÃæµÄ´úÂë»ñµÃµÄÊýÖµ£º

long time=timestamp.getTime()+timestamp.getNanos()/1000000;
ºÁ΢ÃëµÄ²¿·Ö¾ÍÊÇΪʲôһ¸öjava.sql.Timestamp¶ÔÏó²»µÈÓÚÒ»¸öjava.util.Date¶ÔÏ󣬶øÒ»¸öjava.util.Date¶ÔÏó¿ÉÄܵÈÓÚÒ»¸öjava.sql.Timestamp¶ÔÏóµÄÔ­Òò¡£ÕâʹµÃequals·½·¨Ó¦µ±±£³ÖµÄ¶Ô³Æ±»´òÆÆÁË¡£

ʹÓÃjava.sql°üÖеÄʱ¼äÏà¹ØµÄÀàÊÇÖØÒªµÄ£¬µ«ÊÇËüÃÇÒ²¿ÉÄܵ¼ÖÂÈËΪµÄ´íÎó¡£

ÕâÊÇÒòΪ£¬ÕâЩÀàµÄ¸´ÔÓÐÔËäÈ»ÒѾ­ÔÚjavadocÀïÃæÇå³þµÄÃèÊöÁË£¬µ«ÊÇÓÉÓÚÕâЩÀà¿´ÉÏÈ¥ºÜ¼òµ¥¶øºÜÉÙÓÐÈË¿´ÕâЩÎĵµ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 3 ÌõÆÀÂÛ

  1. xiaoku8891 ÓÚ 2010-02-26 17:20:38·¢±í:

    ѧϰѧϰ°¡¡£¡£

  2. uchiha ÓÚ 2010-01-02 22:01:02·¢±í:

    ѧϰ

  3. linux_yang ÓÚ 2006-10-15 03:18:22·¢±í:

    :ha3nd :ha3nd