node.js - Javascript Date inconsistency -


on node server, receive time value client in epoch format (milliseconds since jan 1 1970). feed date() object , print so:

var d = new date(epochtime); var year = d.getfullyear(); var mo = d.getmonth(); var day = d.getday();  console.log("iso:" + d.toisostring() + "  year:" + year + " mo:" + mo + " day:" + day); 

now, weird inconsistency date object. e.g. value of "1437386620207.58" - above console.log prints:

iso:2015-07-20t10:03:40.207z  year:2015 mo:6 day:1 

huh? why dates different?

two problems in code:

  • months zero-based in javascript, i.e. 0 january , 11 december.
  • getday() returns day of week. should getdate() instead return day of month.

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -