개발/Swift
Swift 사용자의 시간제 설정 가져오기
khstar
2019. 5. 28. 23:06
반응형
사용자의 시간제 설정에 따라 날짜를 보여주고 싶었습니다.
그냥 DateFormat으로는 자동으로 안되서 사용자가 설정한 시간제를 가져오는 방법을 찾아봤습니다.
참고 사이트의 내용을 기록하기 위해 코드를 남깁니다.
static func is24Hour() -> Bool {
let locale = NSLocale.current
let timeFormat = DateFormatter.dateFormat(fromTemplate: "j", options:0, locale:locale)!
if timeFormat.contains("a") {
//phone is set to 12 hours
return false
} else {
//phone is set to 24 hours
return true
}
}
반응형