I was trying to build a datepicker program on iPhone. However, the time showed in text is earlier exactly 8 hour than the time I choose.
Here’s the code.
“h”file:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
UIDatePicker *datepick;
IBOutlet UILabel *label;
IBOutlet UITextField *textfield;
}
-(IBAction)button;
@property (nonatomic, retain)IBOutlet UIDatePicker *datepick;
@end
“m”file:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize datepick;
-(IBAction)button {
NSDate *choice = [datepick date];
NSString *words = [[NSString alloc]initWithFormat:@"The date is %@", choice];
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"the title" message:words
delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
label.text = words;
textfield.text = words;
}
Convert selected date to your local timezone