私はイスラムカレンダーを使って日付を表示するUIDatePickerを持っています。 datePickerは値を正しい形式で表示しています。しかし、ユーザー選択をUITextFieldに割り当てると、残念なことに、それと同等の日付がグレゴリオ暦の形式で表示されます。どのようにしてこれを変えてイスラムのカレンダーと同等のものを表示できますか?ここでSwiftのUIDatePickerから適切な形式でカレンダーを表示できません
は、関連するコードです:
//The below code is what displays the dates from the Islamic calendar in the UIDatePicker (and works correctly):
let islamicCalendar = NSCalendar.init(calendarIdentifier: NSCalendarIdentifierIslamic)
let components: NSDateComponents = NSDateComponents()
components.calendar = islamicCalendar
components.year = 10
let currentDate = NSDate()
let maxDate: NSDate = islamicCalendar!.dateByAddingComponents(components, toDate: currentDate, options: [])!
self.datePicker?.calendar = islamicCalendar
self.datePicker?.minimumDate = NSDate()
self.datePicker?.maximumDate = maxDate
これは、ユーザーの選択に変換し、適切なのUITextFieldに割り当てるコードのブロックです:
var selectedDate: String = String()
selectedDate = self.dateformatterDateTime(self.datePicker!.date) as String
myTextField.text = selectedDate
func dateformatterDateTime(date: NSDate) -> NSString {
let dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
return dateFormatter.stringFromDate(date)
}
はあなたがdateformatterDateTimeを開始しているか確認することができ、これを試してみてください、あなたはここにその文を投稿してくださいすることができます。 – Jeet
私の謝罪は、コードが更新されています。 – syedfa
いいえ、どこに宣言したのですか?あなたは 'var dateFormatterDateTime = DateTimeformatter'のような宣言したかもしれません。 – Jeet