Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a string to an NSDate

How is it possible to convert a string to an NSDate on iOS?

like image 568
hugo411 Avatar asked Feb 22 '10 14:02

hugo411


People also ask

How to convert string to NSDate in objective c?

NSString *dateStr = @"20100223"; // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMdd"]; NSDate *date = [dateFormat dateFromString:dateStr]; // Convert date object to desired output format [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"]; ...

How to convert string to date in stored procedure?

SQL Server: Convert string to date explicitly In SQL Server, converting a string to date explicitly can be achieved using CONVERT(). CAST() and PARSE() functions.

How do I convert a string to a date?

Using strptime() , date and time in string format can be converted to datetime type. The first parameter is the string and the second is the date time format specifier. One advantage of converting to date format is one can select the month or date or time individually.

What is en_US_POSIX?

In most cases the best locale to choose is "en_US_POSIX", a locale that's specifically designed to yield US English results regardless of both user and system preferences.


1 Answers

NSString *dateStr = @"20100223";  // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMdd"]; NSDate *date = [dateFormat dateFromString:dateStr];    // Convert date object to desired output format [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"]; dateStr = [dateFormat stringFromDate:date];   [dateFormat release]; 

Hope this will help you.

like image 169
Suresh Thayu Avatar answered Oct 16 '22 02:10

Suresh Thayu