Search code examples
javascriptgettime

Javascript gettime()


I am trying to use gettime to sort my date string. But it is returning some vague values like.

  1. 1428303000000 16/06/2014 16:50
  2. 1389074040000 01/07/2014 16:54

The first date is smaller than second so its no. of milliseconds should also be smaller.

You can also check it on http://www.tutorialspoint.com/cgi-binpractice.cgi?file=javascript_178

So don't know why this is behaving like this.

Any help ?


Solution

  • Test your code if you are correctly creating Date object

    // new Date(year, month, day, hour, minute, second, millisecond);
    
    // Working with date 16/06/2014 16:50
    var foo = new Date(2014, 6, 16, 16, 50);
    foo.getTime(); // 1405518600000
    
    // Working with date 01/07/2014 16:54 
    var foo = new Date(2014, 7, 1, 16, 54);
    foo.getTime(); // 1406901240000
    

    Read more about Date object reference.

    Until we see your code and how do you get from "16/06/2014 16:50" to "1428303000000", I can't help more.