Pergunta

If I set the UIDatePicker's date in countdown mode to "1970-01-01 00:05:00 +0000" it shows [ 1hour | 5min ] - why is that?

Set the date (in a different class):

_countdownTime=[[NSDate alloc] initWithTimeIntervalSince1970:5*60];

Create picker and assign date:

//setup a date picker as countdown picker
    UIDatePicker *countdownPicker = [[UIDatePicker alloc] init];
    [countdownPicker setDate:[NSDate date]];
    [countdownPicker setDatePickerMode:UIDatePickerModeCountDownTimer];
    [countdownPicker setMinuteInterval:5];
    [countdownPicker addTarget:self action:@selector(updateCountdownTimeText:) forControlEvents:UIControlEventValueChanged];

    [countdownPicker setDate:[myAction getCountdownTime]];
Foi útil?

Solução

(This is at least somewhat a guess... I'm not an iOS expert at all.)

Well it sounds like the problem is precisely because you're using a time zone which is GMT+1 - or was in January 1970, anyway.

Basically I think the UIDatePicker is showing you the local time of the given NSDate, with the relevant time zone applied. initWithTimeIntervalSince1970 initializes a date with the given number of seconds since the Unix epoch, which is midnight UTC.

I suggest you set the time zone to UTC:

[countdownPicker setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

Then hopefully it'll show what you expected...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top