问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/16339875/date-formatter-for-the-google-calender-api