Changing hour format

hellow firends!

I took the guide to create a custom service page from here:

but I want to show the schedule hours in 24hr format, like 16:00
instead of 12hr format, like 04:00pm

how can I do it?

I assume it is somewhere here?

// Format schedule times.
function mapTimes(times) {
return times.map(time => {
// Split the time into hour, minute, and seconds sections.
const splitStartTime = (time.startTime).split(“:”);
// Determine if the time is am or pm.
const suffix = splitStartTime[0] < 24 ? ‘am’ : ‘pm’;
// Return the hour, minutes, and suffix texts.
return ${(splitStartTime[0] % 12 + ":" + splitStartTime[1])} ${suffix};
})
}

thank you in advance

1 Like

Hello,

To change it to a 24 hour time period you would remove the %12 in the return statement at the last line, as well as the ${suffix} in that line. Since we dont need it you can remove the whole declaration of const suffix = …

New Code:

// Format schedule times.
function mapTimes(times) {
 return times.map(time => {
 // Split the time into hour, minute, and seconds sections.
 const splitStartTime = (time.startTime).split(":");
 // Return the hour, minutes, and suffix texts.
 return `${(splitStartTime[0] + ":" + splitStartTime[1])} `;
    })
}

Goodluck,
Majd

Thank you very much!!

Hello, please help me, doesnt work for me. Am i doing something wrong?