0

I have drag and drop UIDatePicker from InterfaceBuilder and in .h file i have done the outlet and actions as follows.

- (IBAction)DatePicker:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *dateSelected;
@property (strong, nonatomic) IBOutlet UIDatePicker *datePickerOutlet;

and in appDelegate.m file i have assigned the following parameters to the datePickerOutlet

datePickerOutlet.calendar=[NSCalendar autoupdatingCurrentCalendar];
datePickerOutlet.timeZone=[NSTimeZone defaultTimeZone];

but it is giving time as follows through NSLog

2012-09-03 15:42:45.365 DataTest[4213:207] 2012-09-03 10:10:28 +0000
2012-09-03 15:42:45.366 DataTest[4213:207] Asia/Kolkata

it should give output as

2012-09-03 15:42:45.365 DataTest[4213:207] 2012-09-03 3:42:45 +0000
2012-09-03 15:42:45.366 DataTest[4213:207] Asia/Kolkata

(which is the current time)

How to get the current time??in the picker it is showing correctly but when i select a date NSLog is giving other value..

4

2 回答 2

1

显示的时间为格林威治标准时间,您需要使用 localTimeZone 或手动添加 +0530 小时

datePickerOutlet.timeZone = [NSTimeZone localTimeZone];

使用它来设置本地时区。希望能帮助到你。快乐编码:)

于 2012-09-03T10:25:45.260 回答
0

你试过用-[NSDateFormatter stringFromDate:]格式化NSDate吗?

于 2012-09-03T10:47:05.000 回答