Show date with format

I have:

var date = new Date();

and i have many formats:

var one = 'yy-mm-dd';
var two = '';
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?


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

If not, use Datejs.

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

Need Your Help

Canvas drawImage is inexplicably offset by 1 Pixel

javascript jquery css canvas

I'm working on a canvas game that's using a sprite sheet for the character.

Speed up :visible:input selector avoiding filter

javascript jquery performance jquery-selectors

I have a jQuery selector that is running way too slow on my unfortunately large page: