Last active
December 14, 2015 09:29
-
-
Save anthem001/5065192 to your computer and use it in GitHub Desktop.
Simple JavaScript date parser
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 dateparsed = function(){ | |
| this.date = new Date(); | |
| }; | |
| dateparsed.prototype = function(){ | |
| var getFullDateTime = function(){ | |
| return this.date; | |
| }, | |
| getFullMonth = function(){ | |
| var month=new Array(); | |
| month[0]="January"; | |
| month[1]="February"; | |
| month[2]="March"; | |
| month[3]="April"; | |
| month[4]="May"; | |
| month[5]="June"; | |
| month[6]="July"; | |
| month[7]="August"; | |
| month[8]="September"; | |
| month[9]="October"; | |
| month[10]="November"; | |
| month[11]="December"; | |
| var n = month[this.date.getMonth()]; | |
| return n; | |
| }, | |
| getDayOfWeek = function(){ | |
| var day = new Array(); | |
| day[0] = "Sunday"; | |
| day[1] = "Monday"; | |
| day[2] = "Tuesday"; | |
| day[3] = "Wednesday"; | |
| day[4] = "Thursday"; | |
| day[5] = "Friday"; | |
| day[6] = "Saturday"; | |
| var d = day[this.date.getDay()]; | |
| return d; | |
| }; | |
| return { | |
| getFullDateTime: getFullDateTime, | |
| getFullMonth: getFullMonth, | |
| getDayOfWeek: getDayOfWeek | |
| }; | |
| }(); | |
| /* Implement this on your page (don't forget to include dateParser.js in your script tags) | |
| // create object | |
| var thisdate = new dateparsed(); | |
| // call whichever method you need, set to var, alert, doc.write, or whatever | |
| thisdate.getFullDateTime(); | |
| thisdate.getMonth(); | |
| thisdate.getDayOfWeek(); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment