locked
Date function BUG in JS

    Question

  • Hi, i probably just discover a bug in simple date function in JavaScript.

    var d = new Date(1328915047);
    
    var x = d.toString();

    i create Date object, and put in constuctor a miliseconds since 1970UTC. Then i make string, it should show me a date from 2012 year.
    But, it show me 16 Jan 1970. I discover, it show me dane from 1328915 instead of 1328915047, it cut last 3 numbers.

    Its probably some kind of bug, i dont know what kind, its not using WinRT, it should use base browser JS.

    Anyone can tell me, if iam right? And if its really bug, where to report it?

    Friday, February 10, 2012 11:09 PM

Answers

  • Hi R,

    It is not a bug.  There is a bug in your code. 

             var currentDate = new Date();
             var millseconds = currentDate.getTime();
             var calcDate = new Date(millseconds);
             var dateStr = calcDate.toDateString();
    

    If you run this in your debugger you will see you are not using the correct number of milliseconds.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, February 15, 2012 2:45 PM
    Moderator

All replies

  • Please go through the following link:

    http://www.w3schools.com/jsref/jsref_obj_date.asp

    Monday, February 13, 2012 5:16 AM
  • Hi R,

    It is not a bug.  There is a bug in your code. 

             var currentDate = new Date();
             var millseconds = currentDate.getTime();
             var calcDate = new Date(millseconds);
             var dateStr = calcDate.toDateString();
    

    If you run this in your debugger you will see you are not using the correct number of milliseconds.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, February 15, 2012 2:45 PM
    Moderator