简体   繁体   中英

iOS : Timezone Issue on Local timezone of iPhone device

I have been working on an application that takes dates from server in a certain format as given below.

"2015-02-03 00:00:00"

I want to show them with different UI format using NSDateFormatter but as i change the timezone it show previous day or sometimes next day as i changing timezone. One important thing that server side date can be in any of timezone. So, we don't know what kind of timezone date has. I need help to show this to the date as it is on server not change due to local timezone.

Thanks.

The simplest approach would be to parse it as if it were UTC - making it always valid, and without ever needing DST adjustments - and then format it in UTC as well. In other words, set the time zone of both the formatter and parser to UTC. For types which need a time zone, that's the simplest way of faking "There isn't a time zone here, just treat it all as local to an unspecified time zone."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM