How is it possible to convert a string to an NSDate
on iOS?
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"]; ...
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With