Search code examples
mysqlnode.jsunix-timestampdatetime-conversion

How can I convert datetime : 1518427800 to hh:mm:ss dd/mm/yyyy in node.js?


I am trying to built a attendance app for my college where in I am fetching data for a web time-table application which has a sql backend and there the lecture start time and end time is in format 1518427800. I am not even sure what format is this.

I am using node.js to fetch from mysql and push it in firebase database, but before i pushing it in firebase. i want to convert the datetime format into something that is understandable.

I am not allowed to alter anything in the web application or its database.


Solution

  • It is a unix time stamp and represents the number of seconds since 1970-01-01.

    You can just convert it to a number of milliseconds and pass it to the Date constructor:

    var datetime = new Date(1518427800 * 1000);