javascript get 24 hour time
var date = new Date();
console.log(date.toLocaleString('en-GB'));
javascript get 24 hour time
var date = new Date();
console.log(date.toLocaleString('en-GB'));
12 hours to 24 hours javascript
const time = '5:00AM';
function convertTo24HrsFormat(time) {
const slicedTime = time.split(/(PM|AM)/gm)[0];
let [hours, minutes] = slicedTime.split(':');
if (hours === '12') {
hours = '00';
}
let updateHourAndMin;
function addition(hoursOrMin) {
updateHourAndMin =
hoursOrMin.length < 2
? (hoursOrMin = `${0}${hoursOrMin}`)
: hoursOrMin;
return updateHourAndMin;
}
if (time.endsWith('PM')) {
hours = parseInt(hours, 10) + 12;
}
return `${addition(hours)}:${addition(minutes)}`;
}
console.log(`Converted time: ${convertTo24HrsFormat(time)}`);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us