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 ..
- -(void)viewDidLoad{
- NSDate *now = [[NSDate alloc]init];
- [datePicker setDate:now animated:NO];
- [now release];
- }
-
Then in the method you need to get the date:
- NSDate *selected = [datePicker date];
-
You can get the time of the current 0 time zone. To set the date format, you need to add the following custom format:
- NSDate *selected = [datePicker date];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm +0800"];
- NSString *destDateString = [dateFormatter stringFromDate:selected];
- NSString *message = [[NSString alloc] initWithFormat:
- @"The date and time you selected is: %@", destDateString];
-
This specifies the time format of the UTC + 8 time zone.