Created
August 4, 2014 19:32
-
-
Save timrwood/7cb72d7960d19e889673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var momento = moment(556095600000); // 1987-08-16T07:00:00.000Z | |
var day = momento.date(); // 16 | |
var month = momento.month() + 1; // 8 | |
var year = momento.year(); // 1987 | |
var timeperiods = { | |
year : moment(year, "YYYY").toISOString(), // 1987-01-01T08:00:00.000Z | |
month : moment(month + "-" + year, "MM-YYYY").toISOString(), // 1987-08-01T07:00:00.000Z | |
day : moment(day + "-" + month + "-" + year, "DD-MM-YYYY").toISOString() // 1987-08-16T07:00:00.000Z | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timestamp = new Date(556095600000); // 1987-08-16T07:00:00.000Z | |
var day = timestamp.getUTCDate(); // 16 | |
var month = timestamp.getMonth() + 1; // 8 | |
var year = timestamp.getFullYear(); // 1987 | |
var timeperiods = { | |
year : new Date(year).toISOString(), // 1970-01-01T00:00:01.987Z Off by 17 years | |
month : new Date(year, month).toISOString(), // 1987-09-01T07:00:00.000Z Off by 1 month | |
day : new Date(year, month, day).toISOString() // 1987-09-16T07:00:00.000Z Off by 1 month | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated JSperf to run more optimized versions of the code above while still getting the same final output: http://jsperf.com/moment-js-vs-native-date
Optimized moment.js version:
Optimized native version: