Date formatter for the google calender API [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-11 18:23:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!