- (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];
Moje pytanie jest następne ... Jak określić strefę czasową za pomocą Datepicker w Objective C? teraz, jeśli wybiorę niektóre wartości z DatePicker i naciśnij przycisk, który wyświetla alert - czas jest nieprawidłowy. Jest to prawdopodobnie spowodowane nieprawidłową strefą czasową, ale nie jestem pewien. Cóż, wszelkie pomysły byłyby świetne. Na zdjęciu poniżej można zobaczyć, że wybrałem 2:14 pm (14:14), ale alter mówi, że jest 11:14 i strefa czasowa jest +000Jak określić strefę czasową w UIDatePicker
UPDATE 1 Dodałem kilka zmiany w kodzie, ale nadal nic ...
- (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];
Dodałem kilka zmian w kodzie, ale nadal nic ... – Sapozhnick
Nie ustawiaj th strefy czasowej tylko format daty tj dd/mm/rrrr – Daniel
[dateFormatter setDateFormat: @ "yyyy-MM-dd" na "HH: mm: ss"] - jest tym, czego potrzebuję! Dziękuję bardzo Danielowi – Sapozhnick