Reputation: 85
I am in the process of developing SMS based app. When my app launches I select the last-message-date-time from database and send it to the server and I get back all the messages with date-time > last-message-date-time but because the app and server may not be in the same timezone I can't get the correct result. What is the best way to fix this issue? Please help. Thank you.
This question is the follow up of update SQLite with content of push notification when the app is not running.
Upvotes: 3
Views: 409
Reputation: 3733
To figure out this issue. you need to follow the following steps.
Step 1 : Always keep server time zone in UTC.
Step 2 : once you need to send Date-time to server. first need to convert it to UTC and then send to server so server stored it.
Step 3 : While fetching Date-Time from server, you need convert it with respected Time Zone. where you currently are. like if i am using app from INDIA then i will add +5:30 in receiving date from server. so all country manage same.
Hope this help you
Upvotes: 0
Reputation: 37729
One of the options is to store the time stamp in UTC/GMT on server, and when you get the date from server, convert it to local date object using GMT as formate, then show the user to their local timezone using formatters. ie.
NSDateFormatter
with GMT/UTC as timezone to convert it to NSDate
object in Objective-CNSDateFormatter
with local timezone to show it to user.Keep in mind that NSDate holds the date as independent of timezones so when showing it to user, use any NSDateFormatter to convert it to local or any timezone.
Upvotes: 2
Reputation: 4170
Please first convert your system's timezone to your server's timezone when you select date-time from database then send it to server.
Upvotes: 1