[Code Note] iOS-Get current calendar time, note ios-Get calendar

Source: Internet
Author: User

[Code Note] iOS-Get current calendar time, note ios-Get calendar

I. Code.

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSLog (@ "------- getCurrentTime --- % @", [self getCurrentTime]);} # pragma-mark-obtain the current calendar time output format 15:41:55-(NSString *) getCurrentTime {NSDate * date = [NSDate date]; // The calendar is alendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; // indicates the NSDateComponents * compon component of a date object Ent = [calendar components: NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | region | NSCalendarUnitMinute | region fromDate: date]; // set the time zone [component setTimeZone: [NSTimeZone systemTimeZone]. NSInteger year = [component year]; NSInteger month = [component month]; NSInteger day = [component day]; NSInteger hour = [component hour]; NSInteger minute = [component Minute]; NSInteger second = [component second]; NSString * dateString = [NSString stringWithFormat: @ "% I-% @ % I % @ % 2i: % @ % 2i: % @ % I ", year, month> 10? @ "": @ "0", month, day> 10? @ "": @ "0", day, hour> 10? @ "": @ "0", hour, minute> 10? @ "": @ "0", minute, second> 10? @ "": @ "0", second]; return dateString ;}

 

2. output.

2015-10-22 14:06:16.920 getCurrentTime[11139:215609] -------getCurrentTime---2015-010-22 14:0 6:16

 

 

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.