Last active
August 29, 2015 14:13
-
-
Save johnmurch/7fead0bbf820e1fb1fa2 to your computer and use it in GitHub Desktop.
Print Friendly Javascript (JS) Date - Leading Zeros
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 mL = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
var mS = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']; | |
console.log(mL[2]); // March | |
console.log(mL[7]); // Aug |
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 MyDate = new Date(); | |
var MyDateString = ('0' + (MyDate.getMonth()+1)).slice(-2) + '/' | |
+ ('0' + MyDate.getDate()).slice(-2) + '/' | |
+ MyDate.getFullYear(); |
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 newyears = new Date("2014",0,1); | |
var month1 =newyears.getMonth(); | |
var month2 =newyears.getMonth()+1; | |
var month3 =newyears.getMonth()+2; | |
var month4 =newyears.getMonth()+3; | |
var month5 =newyears.getMonth()+4; | |
var month6 =newyears.getMonth()+5; | |
var month7 =newyears.getMonth()+6; | |
var month8 =newyears.getMonth()+7; | |
var month9 =newyears.getMonth()+8; | |
var month10 =newyears.getMonth()+9; | |
var month11 =newyears.getMonth()+10; | |
var month12 =newyears.getMonth()+11; | |
var quarter1 = Math.floor((month1 + 3) / 3); | |
var quarter2 = Math.floor((month2 + 3) / 3); | |
var quarter3 = Math.floor((month3 + 3) / 3); | |
var quarter4 = Math.floor((month4 + 3) / 3); | |
var quarter5 = Math.floor((month5 + 3) / 3); | |
var quarter6 = Math.floor((month6 + 3) / 3); | |
var quarter7 = Math.floor((month7 + 3) / 3); | |
var quarter8 = Math.floor((month8 + 3) / 3); | |
var quarter9 = Math.floor((month9 + 3) / 3); | |
var quarter10 = Math.floor((month10 + 3) / 3); | |
var quarter11 = Math.floor((month11 + 3) / 3); | |
var quarter12 = Math.floor((month12 + 3) / 3); | |
console.log("Month\t"+"getMonth()\t"+"quarter"); | |
console.log("--------- ---------- -------"); | |
console.log("January\t\t\t"+month1+"\t\t"+quarter1); | |
console.log("February\t\t"+month2+"\t\t"+quarter2); | |
console.log("March\t\t\t"+month3+"\t\t"+quarter3); | |
console.log("April\t\t\t"+month4+"\t\t"+quarter4); | |
console.log("May\t\t\t\t"+month5+"\t\t"+quarter5); | |
console.log("June\t\t\t"+month6+"\t\t"+quarter6); | |
console.log("July\t\t\t"+month7+"\t\t"+quarter7); | |
console.log("August\t\t\t"+month8+"\t\t"+quarter8); | |
console.log("September\t\t"+month9+"\t\t"+quarter9); | |
console.log("October\t\t\t"+month10+"\t\t"+quarter10); | |
console.log("November\t\t"+month11+"\t\t"+quarter11); | |
console.log("December\t\t"+month12+"\t\t"+quarter12); | |
// Month getMonth() quarter | |
// --------- ---------- ------- | |
// January 0 1 | |
// February 1 1 | |
// March 2 1 | |
// April 3 2 | |
// May 4 2 | |
// June 5 2 | |
// July 6 3 | |
// August 7 3 | |
// September 8 3 | |
// October 9 4 | |
// November 10 4 | |
// December 11 4 |
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 yesterday = new Date() | |
yesterday.setDate(yesterday.getDate() - 1); | |
var year = yesterday.getFullYear(); | |
var month = yesterday.getMonth(); | |
var day = yesterday.getDate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment