I am new at iOS development.
I use just simple UILocalNotification
in my apps. I get fire date from UIDatePicker
which has
self.datePicker.datePickerMode = UIDatePickerModeTime
When i set my time by UIDatePicker
then i want to fire date base on UIDatePicker
time
I got is by
NSLog(@"%@", self.datePicker.date);
console : 2013-08-09 10:28:30 +0000 -------> ( wrong time i got.)
So, I convert this time to NSString
by NSDateFormatter
NSDateFormatter *dateFormator = [[NSDateFormatter alloc] init];
[dateFormator setDateFormat:@"h:mm a"];
NSLog(@"%@", [dateFormator stringFromDate:self.datePicker.date]);
console : 3:58 PM -------> ( Here i got proper time)
But in fireDate
property of NSLocalNotification
i need to apply its value as NSDate
, So i again convert NSString (that i got it proper time) to NSDate
.
NSDate *fireDate = [[NSDate alloc] init];
fireDate = [dateFormator dateFromString:[dateFormator stringFromDate:self.datePicker.date]];
console : 2000-01-01 10:28:00 +0000 -------> ( wrong time i got.)
Here Question is How can i set proper time in NSLocalNotification by
UIDatePicker
(with also am/pm) ?
I just need to fire proper time that i got in second console (as NSString
)
Please help me on this issue.
You are confused about what is in the data and what it displays on your console. Specifically, in your second log message you need to format it again.
It seems that the date is OK. So just use it as expected. If you want it to look right in the NSLog statements, you have to format it (which you know how to do). No conversion necessary, just data formatting to display it properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.