0

I am getting the values for sportsEndTime and sportsValueTime in readable format but where as other consoles I am not getting in readable format. Values like 1513752960000 and 1513752960000 are not in readable format. How to convert into readable format in js. Since without readable format Its hard to underrstand the code.

var preEvent = {end: 1513752960000};
var selectedEvent = {start: 1513752960000};
 
let sportsEndTime = new Date(preEvent.end);
console.log("sportsEndTime--->" + sportsEndTime);
//sportsEndTime--->Wed Dec 20 2017 01:56:00 GMT-0500 (Eastern Standard Time)
let sportsValueTime = new Date(selectedEvent.start);
//sportsValueTime--->Wed Dec 20 2017 01:56:00 GMT-0500 (Eastern Standard Time)
console.log("sportsValueTime--->" + sportsValueTime);

console.log("sportsEndTime.getTime()--->" + sportsEndTime.getTime());
//sportsEndTime.getTime()--->1513752960000
console.log("sportsValueTime.getTime()--->" + sportsValueTime.getTime());
//sportsValueTime.getTime()--->1513752960000
console.log("sportsValueTime.getTime()--->" + (sportsValueTime.getTime() - 30000));
//sportsValueTime.getTime()--->1513752930000
console.log("sportsValueTime.setTime(sportsValueTime.getTime() - 30000)--->" + sportsValueTime.setTime(sportsValueTime.getTime() - 30000));
//sportsValueTime.setTime(sportsValueTime.getTime() - 30000)--->1513752930000
RobG
  • 142,382
  • 31
  • 172
  • 209

1 Answers1

0

That's unreadable format called unix timestamps,

var timeStamp = Math.floor(Date.now() / 1000);
// 1513827258

var nDate = new Date(timeStamp * 1000);
// Thu Dec 21 2017 11:34:18 GMT+0800 (W. Australia Standard Time)

using moment.js would make it easier to manage date/time operation.

arespati
  • 36
  • 1
  • 7
  • The OP doesn't have an issue with converting the time value to a Date, but with formatting the date. The OP value is milliseconds, the seconds example is unnecessary. – RobG Dec 21 '17 at 05:50
  • Really? because what I see were 'Values like 1513752960000 and 1513752960000 are not in readable format. How to convert into readable format in js. Since without readable format Its hard to underrstand the code.' – arespati Dec 22 '17 at 10:12