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.