IOS Dateformatter set GMT format time--ios Development Series---the knowledge of growing up in the project four

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.