UIDatePicker 在我打印时显示错误的日期
UIDatePicker showing wrong dates when i printed it
我用 UIDatePicker(时间模式)创建了一个小项目,并将其连接到值更改方法。在该方法中,我将一个 NSLog 与选定的时间一起使用。当我更改 UIDatePicker 的值时,卡纸在我的打印中出现错误的值控制台
例如:
当我选择 9:19 AM 我的控制台打印 2015-04-27 03:49:10 +0000
为什么显示不同的值?
我的代码
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIDatePicker *picker;
- (IBAction)pic:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//Value changed method
- (IBAction)pic:(id)sender {
NSLog(@"%@",self.picker.date);
}
@end
用这个来记录
[self.picker.date descriptionWithLocale:[NSLocale currentLocale]]
由于时区原因导致日志不对,NSDate在显示日期时会自动调整时间偏移
我用 UIDatePicker(时间模式)创建了一个小项目,并将其连接到值更改方法。在该方法中,我将一个 NSLog 与选定的时间一起使用。当我更改 UIDatePicker 的值时,卡纸在我的打印中出现错误的值控制台
例如: 当我选择 9:19 AM 我的控制台打印 2015-04-27 03:49:10 +0000
为什么显示不同的值?
我的代码
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIDatePicker *picker;
- (IBAction)pic:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//Value changed method
- (IBAction)pic:(id)sender {
NSLog(@"%@",self.picker.date);
}
@end
用这个来记录
[self.picker.date descriptionWithLocale:[NSLocale currentLocale]]
由于时区原因导致日志不对,NSDate在显示日期时会自动调整时间偏移