Time zone of DatePicker acquisition time

Source: Internet
Author: User

Date selector:

To load the selector to the current date and time every time the software is loaded, you must create a new NSDate object in viewDidLoad, in this way, this object contains the current time and time. Set datePicker to this date, so that the selector will reset to the current date and time each time this view is loaded from nib ..

 
 
  1. -(void)viewDidLoad{ 
  2.     NSDate *now = [[NSDate alloc]init]; 
  3.     [datePicker setDate:now animated:NO]; 
  4.     [now release]; 
  5.   

Then in the method you need to get the date:

 
 
  1. NSDate *selected = [datePicker date]; 
  2.   

You can get the time of the current 0 time zone. To set the date format, you need to add the following custom format:

 
 
  1. NSDate *selected = [datePicker date]; 
  2.  
  3. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
  4. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm +0800"]; 
  5. NSString *destDateString = [dateFormatter stringFromDate:selected]; 
  6. NSString *message = [[NSString alloc] initWithFormat: 
  7.                          @"The date and time you selected is: %@", destDateString]; 
  8.   

This specifies the time format of the UTC + 8 time zone.

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.