-1

I'm trying to format date in JS as below to formating as Y-m-d But I want to get ymdms.

datestr = current.toISOString().split('T')[0];
resulting_dates.push(datestr);//dates.push(d.toISOString().split('T')[0]);
DMS-KH
  • 2,397
  • 7
  • 32
  • 66

1 Answers1

1

Here is a working example you can modify the date to get your preferred format :

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>
Jay
  • 625
  • 8
  • 33