0

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.

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Since your are not allowed to alter anything in the web application or its database, means you are suppose to change the format in your node.js backend. Why don't you go through the code of the other web app to get the logic it uses to store the dates? – cdaiga Feb 17 '18 at 14:39
  • 2
    1518427800 is an epoch timestamp. It is the number of seconds since jan 1 1970. You may google it for more details. – jose_bacoy Feb 17 '18 at 14:39

3 Answers3

3

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); 
oniramarf
  • 843
  • 1
  • 11
  • 27
trincot
  • 317,000
  • 35
  • 244
  • 286
0

As mentioned in the above answer, it is a UNIX timestamp

Using moment it is very easy to convert into a readable format

const moment = require('moment')

moment(1553939271155).format("DD/MM/YYYY") // outputs "30/03/2019"
moment(1553939271155).format("DD/MMM/YYYY") // outputs "30/Mar/2019"
moment(1553939037562).format("YYYY/MM/DD") // outputs "2019/03/30"
Shekar Mania
  • 307
  • 3
  • 7
0

1518427800 is an epoch timestamp. It is the number of seconds since jan 1 1970.

you can simply convert it into the number of milliseconds

ex. 1518427800*1000

then , pass it to the DATE constructor

ex. var datetime = new Date(1518427800 * 1000);

Rohit Jaiswal
  • 257
  • 4
  • 6