Date Masking of all format using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunita jadhav
    New Member
    • Feb 2008
    • 8

    Date Masking of all format using javascript

    How can i mask the date format for all types of date format in a single function using javascript
  • tswaters
    New Member
    • Feb 2007
    • 19

    #2
    Originally posted by sunita jadhav
    How can i mask the date format for all types of date format in a single function using javascript
    The short answer is you can't... I imagine you want something like,
    [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

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      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

      Working...