Profile豆浆油条BlogLists Tools Help
    October 19

    new Date(0)

    向来只知道new Date(0)是1970年1月1日
     
    今天在laszlo里写new Date(1970,0,1,0,0).getTime()却得到了-28800000的答案,一除,相差了8小时,心想这肯定是因为我们在+8时区了,顿时很迷惑,到底该用new Date(0)还是new Date(1970,0,1,0,0)。
    又在java里写了一个测试,果然,
      Calendar cal = new GregorianCalendar();
      cal.setTime(new Date(0));
      assertEquals(1970, cal.get(Calendar.YEAR));
      assertEquals(0, cal.get(Calendar.MONTH));
      assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
      assertEquals(8, cal.get(Calendar.HOUR_OF_DAY));
      assertEquals(0, cal.getTimeInMillis());
      Calendar cal2 = new GregorianCalendar(1970, 0, 1, 0, 0, 0);
      assertEquals(0, cal2.getTimeInMillis() + cal2.get(Calendar.ZONE_OFFSET));
    想想也对,Date是带着TimeZone信息的,而这个时间0点又不能因为地区的不同而有不同的含义,嗯……这下认识到了
    在laszlo中的写法就是
       var tempt=new Date(1970, 0, 1);
       if (tempt.getTime()==tempt.getTimezoneOffset()*60000);
    而我想,在我需要的这个地方还是用0比较好,而不是各个地区的"0"。

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://b051.spaces.live.com/blog/cns!9E2D0BC71827D4E9!230.trak
    Weblogs that reference this entry
    • None