By using luxon we can define the different time formats as follows.
const customisedTime = (timeStamp) => {
const formatTime = "MM/dd/YYYY hh:mm a";
let formattedDate = timeStamp.toFormat(formatTime);
}
//Example output is : 12/24/2024 09:46 PM
We can convert the above AM/PM to am/pm by the following code
const customisedTime = (timeStamp) => {
const formatTime = "MM/dd/YYYY hh:mm a";
let formattedDate = timeStamp.toFormat(formatTime);
formattedDate = formattedDate.replace(/AM/PM/, date => date.toLocaleLowerCase());
}
//Example output is : 12/24/2024 09:46 pm
in the same we can write different time formats as follows
const formatTime = "MM/dd/YYYY hh:mma"; // 12/24/2024 09:46PM
const formatTime = "dd/MM/YYYY hh:mma"; // 24/12/2024 09:46PM
const formatTime = "MM/dd/YYYY, hh:mm a"; // 12/24/2024, 09:46 PM