- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", selected];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected" message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
Vì vậy, câu hỏi của tôi là tiếp theo ... Làm cách nào để chỉ định múi giờ sử dụng Trình ghi ngày tháng trong mục tiêu C? ngay bây giờ nếu tôi chọn một số giá trị từ DatePicker và nhấn nút hiển thị cảnh báo - thời gian là sai. Đó có thể là do múi giờ không chính xác nhưng tôi không chắc chắn. Vâng bất kỳ ý tưởng sẽ là tuyệt vời. Trên hình ảnh bên dưới, bạn có thể thấy rằng tôi đã chọn 14:14 (14:14) mà là một ALTER nói rằng nó là 11:14 và múi giờ là +000Cách chỉ định múi giờ trong UIDatePicker
UPDATE 1 Tôi đã thêm một vài thay đổi mã của tôi, nhưng vẫn không có gì ...
- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *tz = [NSTimeZone systemTimeZone];
[dateFormatter setTimeZone:tz];
NSString *formattedDate = [dateFormatter stringFromDate:selected];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", formattedDate];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected"
message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[dateFormatter release];
Tôi đã thêm một vài thay đổi mã của tôi, nhưng vẫn không có gì ... – Sapozhnick
Đừng đặt múi giờ thứ chỉ là định dạng ngày tức là MM/dd/yyyy – Daniel
[dateFormatter setDateFormat: @ "yyyy-MM-dd 'tại' HH: mm: ss"] - là những gì tôi cần! Cảm ơn bạn rất nhiều Daniel – Sapozhnick