Today in the project began to take over the client's signature this module, signed this will be at the end of the project to write their own experience!
Today, in the process of signing, we need to send a date value to the server, the format requirement is GMT, which is GMT time!
Format requirement is OCT 10:20:35 GMT
And the format I get through [nsdate Date] is 2015-10-22 10:20:35
So just search the internet for answers.
It is said that the time obtained by [NSDate Date] is the GMT region, so I think it's a problem in the format of the transfer.
But after a try, either in the format or set the time zone (in fact, I am not set) can not get the results I want
1nsdateformatter* Dateformatter =[[NSDateFormatter alloc]init];Ten[Dateformatter Setdateformat:@"dd MM yyyy HH:mm:ss"]; One A -NSString *fixstring =[dateformatter stringfromdate:[nsdate Date]]; - theNSString *datestring = [NSString stringWithFormat:@"%@ GMT", fixstring]; - -Mztlog (@"fixstring = =%@", fixstring); - +Mztlog (@"Nowdate = =%@", [NSDate Date]);
And then communicate with the background, let's help to see the background of the format is how to turn
Finally find the source, originally the format of the conversion is wrong, and also did not set the time zone for Greenwich area
The following are the results I want
nsdateformatter* Dateformatter =[[NSDateFormatter alloc]init]; Nstimezone*timezone = [Nstimezone timezonewithname:@"GMT"]; [Dateformatter Settimezone:timezone]; [Dateformatter Setdateformat:@"d MMM yyyy HH:mm:ss ' GMT '"]; NSString*fixstring =[dateformatter stringfromdate:[nsdate Date]]; Mztlog (@"fixstring = =%@", fixstring); Mztlog (@"Nowdate = =%@", [NSDate Date]);
More specific iOS dateformatter format Daquan can refer to the following article
Http://www.open-open.com/lib/view/open1374292431912.html
IOS Dateformatter set GMT format time--ios Development Series---the knowledge of growing up in the project four