javascript - Customising a JS data object to suit -
i wondering if it's possible customise e.data.date string output that's more suited needs. currently, e.data.date, example, output thu jun 2012 2014 2000:00:00 gmt+0100 (bst) ideally i'd to replicate event start , end date input of 20140607.
e.data.date date object.
i utilize e.data.date.getutcdate() month example, desired output of 20141102, example, includes year, month , date, there doesn't seem getter method...
any ideas?
date.prototype.getcustomformat = function () { homecoming this.getfullyear()+""+getintwodigitformat(number(this.getmonth())+1)+""+getintwodigitformat(number(this.getday())-1); }; function getintwodigitformat(val) { homecoming val < 10 ? '0' + val : val; }
and can phone call new date().getcustomformat();
update 24 sep, 2014:
date.prototype.format = function (format) { var o = { "m+": this.getmonth() + 1, "d+": this.getdate(), "h+": this.gethours(), "m+": this.getminutes(), "s+": this.getseconds(), "q+": math.floor((this.getmonth() + 3) / 3), "s": this.getmilliseconds() }; if (/(y+)/.test(format)) format = format.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length)); (var k in o) if (new regexp("(" + k + ")").test(format)) format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); homecoming format; }; in way can format date how want faster implementing custom library. example:
x=new date(); date {wed sep 24 2014 14:30:22 gmt+0300 (gtb standard time)} x.format('m') "9" x.format('d') "24" x.format('d m') "24 9" x.format('d:m') "24:9" x.format('d:mm') "24:09" x.format('d:mm:yy') "24:09:14" x.format('d:mm:yyy') "24:09:014" javascript date
No comments:
Post a Comment