Date that is not linked to TimeZone

Hello,

I'm creating an app that stores multiple Date objects: the users selects a date and a time and receives a notification at this time precisely.

The problem that happens is after saving a Date, if the device's timezone changes, the Date also changes - and that is not what's I'm expecting (just want the original time as is without depending on timezone).

I have inspected the TimeZone properties when I'm building the Date from DateComponents but nothing has worked.

Thank you for your answer.

By “Date objects” you meant the Foundation Date structure, right?

If so, that type doesn’t include a time zone. It’s underlying storage is a Double, being the time offset in seconds from the reference date, that is, the start of 2001 in GMT.

In the Foundation design, time zones are considered to be a rendering issue. That is:

  • When you use Calendar to convert a Date to DateComponents, the timeZone property affects the values you get back.

  • Likewise when you go the other way.

  • And likewise when you use a DateFormatter, which uses date components operation internally.

  • Or a UI component, like NSDatePicker.

So if your dates shown by your app are changing, it’s nothing to do with the Date values but with how you’re rendering them. How are you doing that?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Date that is not linked to TimeZone
 
 
Q