views:

78

answers:

1
+1  Q: 

convert date/time

Hi everyone,

Right now in my code, I have

$('#StartDateTime').val(new Date(event.start).toLocaleDateString() + " " + (event.start).toLocaleTimeString());

which this displays "Thursday, July 22, 2010 8:00:00 AM". I was wondering if anyone could help me on how I could convert it to just plain "07/22/2010 08:00 am"?

I would appreciate it a lot. Thanks!

+1  A: 

I think you're going to have to end up doing something like this.

Here's an example: http://jsfiddle.net/7exrR/

var date = new Date(event.start);

var m = date.getMonth() + 1;
var d = date.getDate();
var y = date.getFullYear(); 
var t = date.toLocaleTimeString().toLowerCase().replace(/:\d\d ([ap]m) .+$/,' $1');

$('#StartDateTime').val( m + '/' + d + '/' + y + ' ' + t );​​​​​​​​​​​​​​​​
patrick dw
@patrick dw -- thanks!
hersh