2

I have:

var date = new Date();

and i have many formats:

var one = 'yy-mm-dd';
var two = 'dd.mm.yy';
var three = 'dd/mm/yy';
var four = 'mm/dd/yy';

Is possible to showing current date with this four formats? I know - i can use clause IF or SWITCH and set this, but maybe in JavaScript or jQuery without external libraries i can use this format as option?

2 Answers2

1

If you're also already using jQuery UI, there's a string formatter function in the DatePicker.

If not, use Datejs.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
0

You will have to do it yourself by using getFullYear(), getMonth() and getDate() and combining them as you see fit (no jquery/jquery UI required).

If you are using or can use JQuery UI you can take advantage of the $.datepicker.formatDate method (that's the approach we took).

Your question has been asked (in a somehow different form) before

Community
  • 1
  • 1
Ando
  • 11,199
  • 2
  • 30
  • 46