Last active
April 29, 2021 14:56
-
-
Save cicerohellmann/5c84c877f87273e85894cb59ca2fa265 to your computer and use it in GitHub Desktop.
time conversion
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
let amPmFormat = "h:mm a" | |
let twentyFourHFormat = "HH:mm" | |
func hourMinuteParser(date: Date) -> KotlinInt{ | |
let formatter = DateFormatter() | |
if DateFormatter.dateFormat(fromTemplate: "j",options:0, locale: Locale.current)!.contains("a") { | |
formatter.dateFormat = amPmFormat | |
}else{ | |
formatter.dateFormat = twentyFourHFormat | |
} | |
let stringTime = formatter.string(from: date) | |
let time = formatter.date(from: stringTime) | |
formatter.dateFormat = "HH:mm" | |
let time24 = formatter.string(from: time!) | |
let timeWithoutSpecialCharacters = time24.replacingOccurrences(of: ":", with: "") | |
let int2 = Int32(timeWithoutSpecialCharacters) ?? 0 | |
return KotlinInt(int: int2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment