Reputation: 922
Every second I'm updating my chart with new data, where label is correct unix timestamp. Here's options for my x-axis
xAxes: [
{
ticks: {
maxRotation: 0,
minRotation: 0,
},
type: "time",
time: {
displayFormats: {
second: "HH:mm:ss"
}
}
}
],
I'm wondering to get from timestamp 1535577869
something like 21:24:29
but getting 9:32:57.871 pm
Upvotes: 1
Views: 316
Reputation: 13024
A JavaScript timestamp (see Date.now()
) is in milliseconds, not seconds like a Unix timestamp.
To make moment.js recognise your timestamp you probably need to multiply it by a thousand (since Chart.js is passing your value to moment.js):
1535577869 * 1000
If you were creating a moment directly you could specify an input format:
moment(1535577869, 'X');
Upvotes: 1