Created
August 17, 2020 09:46
-
-
Save Cihatata/ad13d4228840da8e2c32e830eebb2650 to your computer and use it in GitHub Desktop.
Time Conversion AM/PM Convert Javascript HackerRank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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