0

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.

1 Answers1

0

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.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • i just want to fire date as **console : 3:58 PM -------> ( Here i got proper time)** –  Aug 09 '13 at 10:43
  • @RanjuPatel The above is not an understandable English sentence. – Mundi Aug 09 '13 at 10:45
  • how can i convert **3:58 PM** to proper time? so, i m able to fire notification. (with notification.fireDate ) ? –  Aug 09 '13 at 10:52
  • You do not need to convert it. Use the proper time from the date picker. I can show you how to convert a string into a date - but a time does not have a date - you need to add the date part as well. – Mundi Aug 09 '13 at 10:56
  • Thanks sir its work form me,, so stupid question is this :( please update your answer so, in future might be it is helpful for other developer. –  Aug 09 '13 at 11:06