Created
October 9, 2010 03:38
-
-
Save ryantenney/617851 to your computer and use it in GitHub Desktop.
rfc1123 date formatter
This file contains 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
;(function () { | |
var dayNames = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"], | |
monthAbbr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | |
// ddd, dd MMM yyyy HH:mm:ss GMT | |
Date.prototype.rfc1123 = function () { | |
var self = this, | |
getVal = function (name) { | |
var val = "" + self["get" + name](); | |
return val.length > 1 ? val : "0" + val; | |
}; | |
return dayNames[+getVal("Day")] // ddd | |
+ "day, " | |
+ getVal("Date") // dd | |
+ " " | |
+ monthAbbr[+getVal("Month")] // MMM | |
+ " " | |
+ getVal("FullYear") // yyyy | |
+ " " | |
+ getVal("Hours") // HH | |
+ ":" | |
+ getVal("Minutes") // mm | |
+ ":" | |
+ getVal("Seconds") // ss | |
+ " GMT"; | |
}; | |
}()); |
This file contains 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
;(function(){var c=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Date.prototype.rfc1123=function(){var e=this,a=function(b){b=""+e["get"+b]();return b.length>1?b:"0"+b};return c[+a("Day")]+"day, "+a("Date")+" "+d[+a("Month")]+" "+a("FullYear")+" "+a("Hours")+":"+a("Minutes")+":"+a("Seconds")+" GMT"}}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment