I need to convert the current timestamp (Eg: 1578293326452) to yyyy-mm-dd hh:mm:ss format using javascript. I obtained the current timestamp as follows:
var date = new Date();
var timestamp = date.getTime();
How can I change the format?
I need to convert the current timestamp (Eg: 1578293326452) to yyyy-mm-dd hh:mm:ss format using javascript. I obtained the current timestamp as follows:
var date = new Date();
var timestamp = date.getTime();
How can I change the format?
function getTime(){
  var date = new Date();
  
  var year = date.getFullYear();
  var month = (date.getMonth() +1);
  var day = date.getDate();
  
  var hour = date.getHours();
  var minute = date.getMinutes();
  var second = date.getSeconds();
  
  return formateTime(year, month, day, hour, minute, second);
}
function formateTime(year, month, day, hour, minute, second){
  return makeDoubleDigit(year) + "-" + 
         makeDoubleDigit(month) + "-" + 
         makeDoubleDigit(day) + " " + 
         makeDoubleDigit(hour) + ":" + 
         makeDoubleDigit(minute) + ":" + 
         makeDoubleDigit(second);
}
function makeDoubleDigit(x){
  return (x < 10) ? "0" + x : x;
}
console.log(getTime()) 
    
    Maybe this is what you need
d = Date.now();
d = new Date(d);
d = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear()+' '+(d.getHours() > 12 ? d.getHours() - 12 : d.getHours())+':'+d.getMinutes()+' '+(d.getHours() >= 12 ? "PM" : "AM");
console.log(d);
