2015-04-30 137 views

回答

1

要絕對確定我會將字符串拆分爲非正整數的字符\D+。然後,你必須與所有部件的數組,你可以把它傳遞到new Date()以正確的順序:

var aParts = '19/04/2015:21:43:47.40'.split(/\D+/); 
 
document.write(new Date(aParts[2], parseInt(aParts[1], 10)-1, aParts[0], aParts[3], aParts[4], aParts[5], aParts[6]));

+0

@Nic如果你使用這個,有在那裏,因爲一個錯誤的JavaScript計數從0到11的月份,因此第4月被解釋爲5月應該是4月。我通過在找到的部分中減去1後將其固定在我的答案中。 – funkwurm

相關問題