我试图在 iPhone 上构建一个 datepicker 程序。但是,文本中显示的时间比我选择的时间早 8 小时。这是代码。
“h”文件:
#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”文件:
#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;
}