My database uses MongoDB and has a timestamp field with unique formats, such as:
1657479170.7300725
1657479170.7301126
1657479170.7301197
1657479170.9120467
1657479170.932398
Converting these timestamps to the date format YYYY-MM-DD yields the correct results. For instance, the first timestamp converts to:
10.07.2022 21:52:50
However, when attempting to convert in JavaScript, the output is:
1970-01-20 06:24:39
which is not the expected value.
Conversion code snippet:
ConvH.forEach(conv => {
conv.tracker.events.forEach(element => {
console.log(parseFloat( parseFloat(element.timestamp.toFixed(4))), moment(new Date( parseFloat( element.timestamp.toFixed(4)))).format("YYYY-MM-DD HH:mm:ss"));
element.timestamp = new Date(element.timestamp).toLocaleString();
})
});
Please note that new Date(element.timestamp).toLocaleString(); yields the same result.