1

Possible Duplicate:
how to format javascript date

I have the following bit of code

 $('#ins_date').attr('value', Date());

What i get is this : Wed Mar 21 2012 17:52:32 GMT+0100 (Romance Standard Time)

How could i format this string to get somethingh like this : 2012-03-01

Community
  • 1
  • 1
Gunnit
  • 996
  • 4
  • 21
  • 44

2 Answers2

1

date.js is the best I've found. It supports many different formats.

Davin Tryon
  • 62,665
  • 13
  • 135
  • 126
-1

Best option for now is using moment.js library. Formatting for native Javascript Date is not well supported.

var now = moment();
now.format("YY-MM-DD");
$('#ins_date').attr('value', now);
Frank van Wijk
  • 3,065
  • 18
  • 39