How can i mask the date format for all types of date format in a single function using javascript
Date Masking of all format using javascript
Collapse
X
-
Tags: None
-
Originally posted by sunita jadhavHow can i mask the date format for all types of date format in a single function using javascript
[code=javascript]
var myDate = new Date()
specialFormat = myDate.mysterio usMissingFuncti on("yyyy-mm-dd")
// returns 2008-02-26
[/code]
Some may say the holy grail of javascript is event handling... I disagree, date handling is way harder.... the good news there's lots of people out there with the same or a similar problem.... you can always try google -
i dont know about all formats, but this hits a lot of them:
Code:function parseDate(s) { if (s.match(/^\s?\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}:\d{2}Z\s?$/g)) { } var d = new Date(); try { d.setTime(Date.parse(s)); } catch (t) { var td = s.replace(/[-_\\.]/gm, "/").replace(/T!h+/, " "); d.setTime(Date.parse(td)); } return d; }
Comment
Comment