Chart for timestamp, way of display #45
-
For the time-stamp in Chart with x-axis, Time display for 13:10:10
Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
graphieros
Jul 2, 2024
Replies: 1 comment 3 replies
-
Hi @manulsan ^^ There is no formatting made by the library for timestamps, it only displays the strings you pass to the config. I recommend you use your own formatting function (or use a library for that). function convertTimestampToAmPm(timestamp) {
const timestampRegex = /^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
const match = timestamp.match(timestampRegex);
if (!match) {
return "Invalid timestamp format. Please use 'YYYY/MM/DD HH:MM:SS'.";
}
const [_, year, month, day, hoursStr, minutesStr, secondsStr] = match;
const date = new Date(`${year}-${month}-${day}T${hoursStr}:${minutesStr}:${secondsStr}`);
let hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const amPm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes;
const formattedSeconds = seconds < 10 ? '0' + seconds : seconds;
const formattedTime = `${hours}:${formattedMinutes}:${formattedSeconds} ${amPm}`;
return formattedTime;
}
console.log(convertTimestampToAmPm('2024/07/02 13:17:06')) // Result: "1:17:06 PM" |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
graphieros
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @manulsan ^^
There is no formatting made by the library for timestamps, it only displays the strings you pass to the config.
I recommend you use your own formatting function (or use a library for that).
Here is a function you can use to format your time: