0

1) I am getting the date from the google calender. The format is 2013-05-03T22:30:00.000+02:00 like this. Which date format used for this type of date in the app.

2) I have to show the date like this format Feb 4th 2013 .

How to implement these two features in the my app? Please help me.

Thank you.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mani
  • 1,310
  • 1
  • 20
  • 40

2 Answers2

2

To get the NSDate from that string:

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS Z"];
 NSDate *myDate = [dateFormat dateFromString:@"2013-05-03T22:30:00.000+02:00"];

Once you have your NSDate, you can do the same to get the representation:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:"MMM d yyyy"];
NSString *myString = [myDate stringFromDate:myDate];

You can consult the whole date formatting options here:

Date Formatter Guide

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • 1
    It's important that the 1st date formatter's locale be set to the special `en_US_POSIX` locale. – rmaddy May 02 '13 at 14:48
1

The date is in RFC3339 format. I suggest you to check this gist where you can see a category on NSDate called NSDate (InternetDateTime). This will do the formatting for your input.

For your second question, check the usage of NSDateFormatter.

Community
  • 1
  • 1
atxe
  • 5,029
  • 2
  • 36
  • 50