date.format returning error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    date.format returning error

    I'm a .net developer by trade and obviously not great at javascript. can anyone tell me why this is receiving this error?

    Code:
    var myDate = new Date();
    alert(myDate.format('mm/dd/yy'));
    ERROR = 'Object doesn't support this property or method'
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    format() is not a method of the Date object.

    use toLocaleDateStr ing() (if your browser supports that) or prototype your own format() method.

    Comment

    • yarbrough40
      Contributor
      • Jun 2009
      • 320

      #3
      lol... I guess that makes sense then. all of my googling has been telling me to use that method. I wonder what I've been misreading.... ::?::

      Anyway here is a pointed easy question then: What is the best method to use to format a date object?

      (it's funny how the simpelest things can drive you nuts...)

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        right on..... I'll try to jerry-rig my own format : ) thanks much

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Originally posted by yarbrough40
          right on..... I'll try to jerry-rig my own format :
          have you ever done JavaScript prototyping?

          PS. I think you found C#’s Date.format()

          Comment

          • yarbrough40
            Contributor
            • Jun 2009
            • 320

            #6
            thanks - nope this is the first I've ever heard of such a thing. sounds pretty fancy!

            btw. I ended up formatting my date by stringing together myDate.getMonth () + '/' + myDate.getDate( ) + '/' + myDate.getFullY ear()

            Comment

            • Joshua faulkenb
              New Member
              • Nov 2010
              • 1

              #7
              Check out this library that extends the existing implementation of the JavaScript Date Object. Besides providing a powerful formatting method, it has several other cool features as well!

              Comment

              Working...