Append time to JQuery datepicker?

lhan picture lhan · May 29, 2013 · Viewed 13.3k times · Source

I'm trying to follow this example in order to append the current time to my input when a date is chosen with the datepicker. According to the example, I should just be able to append my time string in the dateFormat option:

$("#entry_date").datepicker({dateFormat: $.datepicker.W3C + date_obj_time}); 

However, in my test (fiddle here), the "M" in "AM" or "PM" is turning into the actual month name. For example, if I specify a date format such as this:

$("#DueDate").datepicker("option", "dateFormat", "mm/dd/yy 9:16 AM" );

I end up with this in my text field:

05/14/2013 9:16 A.May.

Is there a workaround for (or better way to do) this, or am I doing something blatantly wrong?

Answer

freejosh picture freejosh · May 29, 2013

You need to escape the M by wrapping it in single quotes.

Updated fiddle.

The API isn't very obvious as doesn't list it as an "escape" sequence but it lists '...' as being interpreted as "literal text".