2015-12-06 8 views
-1

Я пытаюсь отформатировать дату в JS, как показано ниже, в формате Y-m-d Но я хочу получить ymdms.Как отформатировать дату в Javascript?

datestr = current.toISOString().split('T')[0]; 
resulting_dates.push(datestr);//dates.push(d.toISOString().split('T')[0]); 
+0

http://momentjs.com/ – Jonathan

+0

Вы можете найти ответ здесь: http://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date –

ответ

1

Вот рабочий пример можно изменить дату, чтобы получить нужный формат:

jsfiddle

<button onclick="myFunction();">Try it</button> 

<p id="demo"></p> 

<script> 

function myFunction() { 
var currentdate = new Date(); 
var currentdate = new Date(); 
var datetime = currentdate.getDate() + "/"+ (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " "+ currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); 
document.getElementById("demo").innerHTML = datetime; 
} 

</script> 
Смежные вопросы