- (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];
Así que mi pregunta es siguiente ... ¿Cómo puedo especificar un huso horario usando un Datepicker en Objective C? ahora si elijo algunos valores de DatePicker y presiono el botón que muestra una alerta: la hora es incorrecta. Probablemente se deba a una zona horaria incorrecta, pero no estoy seguro. Bueno, cualquier idea sería genial. En la imagen siguiente se puede ver que he elegido 14:14 (14:14), pero un alter dice que es 11:14 y la zona horaria es 000Cómo especificar un huso horario en UIDatePicker
ACTUALIZA 1 he añadido unos cuantos cambios en mi código, pero todavía no hay nada ...
- (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];
he añadido algunos cambios en mi código, pero todavía no hay nada ... – Sapozhnick
no puedo establecer ª zona horaria sólo el formato de la fecha es decir MM/dd/aaaa – Daniel
[dateFormatter setDateFormat: @ "aaaa-MM-dd" en 'HH: mm: ss "] - ¡es lo que necesito! Muchas gracias Daniel – Sapozhnick