0

In cocoa, I have given a textual NSDatePicker and a disclosure (for displaying graphical date and time pop over) in GUI. When i select a date and time, in text field i'm getting the correct date and time in the format(dd/MMM/yyyy HH:mm). But when I try to get the textfield value in console I'm getting in yyyy-MM-dd hh:mm:ss 0000+. moreover the time is 5:30 hrs less. i want in dd/MMM/yyyy HH:mm format only with the correct timings.

user1999892
  • 135
  • 1
  • 8
  • When putting the date value in the text field, how are you transforming your `NSDate` to `NSString`? – Ismael Feb 08 '13 at 12:05
  • Please provide code snippets. – James Boutcher Feb 08 '13 at 12:05
  • I tried with NSDate and used stringFromDate. – user1999892 Feb 08 '13 at 12:14
  • @property (retain)NSDate *fromDate; NSLog(@"%@",_fromDate); NSDateFormatter *projectFormat = [[NSDateFormatter alloc] init]; [projectFormat setDateFormat:@"dd/MMM/yyyy HH:mm"]; NSString *createdDateStr = [projectFormat stringFromDate:_fromDate]; NSLog(@" der %@",createdDateStr); It is in stringFromDate. But i need it in dateFrom String – user1999892 Feb 08 '13 at 12:26
  • Printing out a `NSDate` object will always format it default way, in GMT (+0), which is what you're doing in `NSLog(@"%@",_fromDate); `. Is that your problem, in that you want those dates to display with a certain time zone and format? (Which you're doing in the second NSLog you're using, so, I'm confused I guess...) – James Boutcher Feb 08 '13 at 12:36
  • You may want to read this: http://stackoverflow.com/a/8866731/928963 – James Boutcher Feb 08 '13 at 12:44
  • possible duplicate of [Getting date from \[NSDate date\] off by a few hours](http://stackoverflow.com/questions/8466744/getting-date-from-nsdate-date-off-by-a-few-hours) – jscs Feb 08 '13 at 18:45

0 Answers0