Subhojit Subhojit - 27 days ago 8
React JSX Question

Firebase Timestamp showing the date of 1970

I want to get the current date and time from the firebase. Applying the following code while console logged I got the date of 1970. How to get the current date and time?

firebase.database().ref("/.info/serverTimeOffset").on('value', function(offset) {
var date = new Date(offset.val());
console.log(date);
});

Answer Source

use below line

Date.now() + offset.val()        

Then the code look like below

firebase.database().ref("/.info/serverTimeOffset").on('value', function(offset) {
 var date = new Date(Date.now() + offset.val());
 console.log(date.toString());  
});