Skip to content

Instantly share code, notes, and snippets.

@Cihatata
Created August 17, 2020 09:46
Show Gist options
  • Save Cihatata/ad13d4228840da8e2c32e830eebb2650 to your computer and use it in GitHub Desktop.
Save Cihatata/ad13d4228840da8e2c32e830eebb2650 to your computer and use it in GitHub Desktop.
Time Conversion AM/PM Convert Javascript HackerRank
function timeConversion(s) {
let timeArr = s.split(":");
let sec = (timeArr[2][0] + timeArr[2][1]);
let timeFormat = s.slice(-2);
let time = {
hours: timeArr[0],
min: timeArr[1],
sec,
timeFormat,function timeConversion(s) {
let timeArr = s.split(":");
let sec = (timeArr[2][0] + timeArr[2][1]);
let timeFormat = s.slice(-2);
let time = {
hours: timeArr[0],
min: timeArr[1],
sec,
timeFormat,
}
if (timeFormat === "PM" && parseInt(time.hours) != 12) {
time.hours = parseInt(time.hours) + 12;
} else if (timeFormat === "AM" && parseInt(time.hours) == 12 ){
time.hours = "00";
}
console.log(time.hours + ":" + time.min + ":" + time.sec);
};
let time = "07:05:45PM";
timeConversion(time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment