Ricevo una variabile stringa con data nel formato 6/1/2012
, voglio convertirla in 01 Jun 2012
. JS FIDDLE DEMOJavaScript converte la stringa in data con il formato (gg mmm aaaa), 01 giu 2012
Codice ho provato:
var t_sdate="6/1/2012";
var sptdate = String(t_sdate).split("/");
var myMonth = sptdate[0];
var myDay = sptdate[1];
var myYear = sptdate[2];
var combineDatestr = myYear + "/" + myMonth + "/" + myDay;
var dt = new Date(combineDatestr);
var formatedDate= dt.format("dd mmm yyyy")
alert(formatedDate);
Ottenere uscita come 01 000 2012
, richiesto come 01 Jun 2012
Unchaught TypeError: Object [object Date] non ha alcun metodo 'format' era l'errore registrato nella console. Il codice che hai funzionerà se includi il plugin dateformat-js nel tuo codice. –
non sto usando alcun file js esterno, è possibile farlo senza usare alcun file esterno –
Guarda questo: http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript?rq=1 – alun