A collection of time conversion methods in IOS development _ios

Source: Internet
Author: User
Tags current time dateformat

When developing an iOS program, sometimes you need to adjust the time format to the format that you want, and we can use the NSDateFormatter class to handle it.
For example:

Instantiate a NSDateFormatter object
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
Set the time format, where you can set the format you want
[Dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];
The current time of the system can be obtained with [NSDate Date]
NSString *currentdatestr = [dateformatter stringfromdate:[nsdate Date]];
The output format is: 2010-10-27 10:22:13
NSLog (@ "%@", currentdatestr);
Don't forget to release the Alloc object after you do not use it
[Dateformatter release];

iOS converts timestamp to time string class method code

Copy Code code as follows:

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

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.