1

I'm sure I'm just being dim, but I can't work out how to use the formatDate utility function of the Mobiscroll date picker plugin.

The doc just says this:

formatDate function(format, date, settings) Format a date into a string value with a specified format

When the value of my input field changes I want to format the value and store it in another field, so I've attempted the following:

<input type="text" id="startTimeInput" onChange="alert(jQuery('#startTimeInput').formatDate('yyyy-MM-dd HH:mm:ss', this.value, ''));"/>

However, the alert never fires and for some reason Firebug is playing up for me right now and as such isn't reporting anything either. Anybody got any ideas?

Note: I'm using jQuery() as I have to use jQuery.noConflict()

Community
  • 1
  • 1
Matt Lacey
  • 8,227
  • 35
  • 58

1 Answers1

3

You should use it as:

jQuery.scroller.formatDate('yyyy-MM-dd HH:mm:ss', new Date(this.value));

Edit:

Second parameter for formatDate must be a date object, not a string.

new Date(this.value) form my example may work for some date formats, but not always.

If you want to convert it first to date (and you know the format) use:

jQuery.scroller.formatDate('yyyy-MM-dd HH:mm:ss', jQuery.scroller.parseDate(yourInputFormat, this.value));
istvan.halmen
  • 3,320
  • 1
  • 23
  • 29
  • Thanks — still not quite there, even if I just use 'yyyy' for the format I get no alert, but if I do YYYY (which must be incorrect for substitution) I see an alert with the string 'YYYY'. – Matt Lacey Sep 21 '11 at 08:12
  • The former worked correctly, thanks! Only issue now is that it's returning the month names instead of the custom strings I provided (01-12) but that can wait for tomorrow. Also need to re-jig the wheels as it seems to have an American bias ;) – Matt Lacey Sep 21 '11 at 11:06