2013-12-19 66 views
0

我想從YY-MM-DD更改日期格式順序DD-MM-YY如何日期格式轉換的Javascript

我怎麼能做到這一點的Javascript?

我已經試過

var now = new Date(); 

now.format("mm-dd-yy"); 

但它不是爲我工作

+1

如果你想'DD-MM-yy',那麼爲什麼你的代碼說'MM-DD-yy'? –

+0

您是否已經有yy-mm-dd格式的日期,或者您現在想要做什麼? –

+0

沒有這麼難檢查互聯網... http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3 – SushiiBalboha

回答

1

下面是一個簡單明瞭的方法

var now = new Date();  
var dd = now.getDate(); //returns date 
var mm = now.getMonth()+ 1; //returns month and you need to add1 because it is array 
var yy = now.getFullYear(); //returns full year 
var st = dd + '-' + mm + "-" + yy; //format as string 
0
var dateFormatted = (now.getMonth()+1)+"-"+now.getDate()+"-"+now.getFullYear(); 
0

您可以使用以下提到的功能,格式日期

utilities.FormatDate(new Date(),"GMT", "dd/MM/yyyy") 
+0

...如果您使用Google Apps,即是。 – JJJ

0
function dateformat(date) 
{ 
    var yourdate = new Date(date); 
yourdate = yourdate.getDate() + '-' + yourdate.getMonth() +1 + "-" +yourdate.getFullYear(); 
} 

使用 - 或/只要你喜歡