get date and time from timestamp in js

 

function getDateTime(MatchTimeStamp){
    var date = new Date(MatchTimeStamp);
var Hours = date.getHours() >12 ? date.getHours()-12 : date.getHours();
var ampm = date.getHours() >= 12 ? ‘pm’ : ‘am’;
var fullDate = `${date.getDate()}${date.getMonth()+1}${ date.getFullYear()}`;
var fullTime = `${Hours}:${date.getMinutes()} ${ampm}`;
return {‘date’: fullDate , ‘time’ : fullTime}
}

Leave a Comment

Your email address will not be published. Required fields are marked *