0
dateFormat 문자열을 자동으로 가져올 방법이 있습니까?NSDateFormatter가 자동으로 dateFormat을 얻습니다. (Swift 2)
///getting the date from datePicker
func handleDatePicker(sender: UIDatePicker) {
let timeFormatter = NSDateFormatter()
timeFormatter.locale = NSLocale.currentLocale()
timeFormatter.dateStyle = .MediumStyle
timeFormatter.dateFormat = "dd MMM yyyy" ///get this automatically???
dateTextField.text = timeFormatter.stringFromDate(sender.date)
}
[...]///other stuff
let dateString = dateTextField.text
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy" //can I get the string automatically based on user locale??? so I don't have to worry about setting the correct string?
dateFormatter.locale = NSLocale.currentLocale()
let dateFromString = dateFormatter.dateFromString(dateString!)
print(dateFromString)/// gives nil if dateFormatter.dateFormat = "dd MMM yyyy" is commented out
날짜를 설정하지 않으면 얻을 수있는 항목은 무엇입니까? – Sofeda
내가 설정하지 않으면 아무렇지 않게 나타납니다. 위와 같이 설정하면 날짜가 올바르게 표시됩니다. 하지만 사용자 환경 설정에 따라 문자열을 자동으로 가져 오려고합니다. –
사용자 선호 날짜 형식 가져 오기 – Sofeda