xcode - Displaying the Day Of The Week From Date Picker -
i want store day of week string using datepicker in xcode using swift.
import uikit class viewcontroller: uiviewcontroller { @iboutlet weak var mydatepicker: uidatepicker! @iboutlet weak var strweekday: uilabel! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. // set mode date mydatepicker.datepickermode = uidatepickermode.date // add target trigger update function change weekday when user changes date mydatepicker.addtarget(self, action: selector("triggerupdate:"), forcontrolevents: uicontrolevents.valuechanged) // weekday initial value self.strweekday.text = mydatepicker.date.weekdayname } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func triggerupdate(sender: anyobject) { self.strweekday.text = mydatepicker.date.weekdayname } } extension nsdate { // returns weekday name (sunday-saturday) string var weekdayname: string { let formatter = nsdateformatter(); formatter.dateformat = "eeee" return formatter.stringfromdate(self) } }
Comments
Post a Comment