我試圖在iPhone上構建一個datepicker程序。然而,文字顯示的時間比我選擇的時間早8小時。 這是代碼。UIDatePicker提前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;
}
?什麼是輸出,你期望什麼?可能你正在尋找'NSDateFormatter'來格式化你想要的日期。 – skram
我選擇日期如6月7日...,但是6月6日...顯示。 – coolhongly