我有以下代码。我按以下格式“2013-07-16T00:00:00”获得{{createDate}}和{{expDate}}。我怎么能以这样的格式转换它们:2013-07-16
<script type="text/javascript">
$(document).ready(function () {
$('#domainName').typeahead({
limit: 5,
remote:{
url: '/rest/search/domains',
filter: function(parsedResponse) {
return parsedResponse.data;
}
},
prefetch: '/rest/search/domains',
template: [
'<p class="repo-language"><span class="">',
'</span> <strong>{{domainName}}</strong><span class="pull-right label label-success">Paid</span></p>',
'<p class="repo-name"><small>{{userName}} / {{userEmail}}</small></p>',
'<p class="repo-description"><small class="text text-success">Create Date: {{createDate}}</small></p>'+
'<p class="repo-description"><small class="text text-danger">Expire Date: {{expireDate}}</small></p>'
].join(''),
engine: Hogan
}).on('typeahead:selected', function (obj, datum) {
console.log(datum);
});
});
答案 0 :(得分:1)
在javascript中尝试以下操作。
var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; //January is 0! var yyyy = today.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} var today = dd+'/'+mm+'/'+yyyy; document.getElementById("DATE").value = today;
检查出来:
var from = "2013-07-16T00:00:00";
date = from.split("T");
alert(date[0]); //gives 2013-07-16
Here是一个有效的例子
希望这有帮助