2016-03-08 38 views
-1

我想在我的網站上更改日期格式。其實目前我正在得到這樣的結果:(3月17日下午1:00),我想要這樣改變它:(2016-03-17)。我搜索了很多網站,這個網站沒有轉換。請幫忙。如何在jQuery中將日期格式更改爲YYYY-MM-DD?

我的代碼:

var editStart1 = $('#modal-startdate').text();---> Getting the date (Mar 17th 1:00 PM) 
$('#datepicker2').val(editStart1);---> (Trying to covert the date format to 2016-03-17) 
$('#fullCalModal').modal('toggle'); 
$('#meeting').modal(); 
+0

哪裏初始值從何而來?如果在服務器上動態生成數據屬性,那麼使用格式化日期值的數據屬性會更好。請注意,需要包括一年 – charlietfl

回答

0

,你必須使用dateFormat

例如:

$(".selection").datepicker({ dateFormat: 'yyyy-mm-dd' }); 
相關問題