Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS how to set date format [duplicate]

Tags:

ios

nsdate

I have a string like this

NSString *datestr = @"2013-08-06T03:51:54+00:00";

I try to set dateformat as below:

NSDateFormatter *dformat = [[NSDateFormatter alloc]init];

[dformat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];

NSDate *date = [dformat dateFromString:datestr];

But the date will be nil, so, can anyone tell me how to set the dateformat, thx!

like image 237
billwang1990 Avatar asked Aug 07 '13 08:08

billwang1990


People also ask

How do I fix the date format on my iPhone?

Once the General settings page is open, tap on Language & Region. On the Language & Region page, you'll find multiple options like Region, Calendar, Temperature, Measurement System, First Day of Week, and Date Format.

How do I change the date format in Apple?

On your Mac, choose Apple menu > System Settings, click General in the sidebar, then click Language & Region on the right. (You may need to scroll down.) Click the pop-up menu next to Region, then choose a geographic region to use the region's date, time, number, and other formats.

How do you repeat automation on iPhone?

Using the Repeat actionPlace the actions that you want to repeat between the Repeat and End Repeat markers, then specify the number of times you want the action to repeat. When the shortcut runs, the actions placed between the markers loop the number of times that you specify.


1 Answers

Try this:

 NSDateFormatter *dformat = [[NSDateFormatter alloc]init];

[dformat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];

NSDate *date = [dformat dateFromString:datestr];

Add ZZZ to the end of your formatter.

like image 119
Abdullah Shafique Avatar answered Oct 09 '22 09:10

Abdullah Shafique