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
  • 1,064
  • 5
  • 22
  • 45

2 Answers2

1

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

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
-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,234
  • 20
  • 41