Converting a Date String to a Required Date String Format

I parsed the .ics file and got the start date as a string, the string contains a value similar to this 20100803T130451Z (this is a formatted date string), I want to convert this string to my required string format ....

My required date string format (tuesday - may 25,2010 (for example))

Can anyone help me? Thanks in advance.

+3
source share
2 answers

Ole is right, here is a sample code.

It:

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd'T'HHmmss'Z'"];
NSDate* date = [dateFormatter dateFromString:dateString];

should convert NSString to NSDate. To get the date format you want, you can change the dateFormat NSDateFormatters date. Like this:

[dateFormatter setDateFormat:@"dddd - MMMM dd,yyy"];
NSString* myNiceLookingDate = [dateFormatter stringFromDate:date];
[dateFormatter release];

This should work, although I have not tested it, but it will at least bring you closer to the result.

have fun, phil.

+5
  • NSDateFormatter, NSDate.
  • NSDateFormatter ( ), NSDate .
+1

Source: https://habr.com/ru/post/1758006/


All Articles