Syncing data from iphone to the server Datetime question - iphone

I want sync data from iphone to the webs server. My question is how can I know which data is new? the only way I see this is by making a datafield for each record on the server and the iPhone, but how about if the Iphone user is in a different timezone or his datetime is different from the server datetime.

Store all of your dates in GMT on both the server and device. There are several methods for getting GMT easily in Objective-C. The device will determine time-zone based on location. If you need to convert to local time, you can get the date by using the NSTimeZoneClass:
[NSDate dateWithTimeIntervalSinceNow:[[NSTimeZone defaultTimeZone] secondsFromGMT]]
Check out the docs on Date and Time Programming for additional assistance.

Related

How to get Local city TimeZone and upload it to firestore as Date Or Timestamp

I have a small issue dealing with dates here, I have a multiplatform app using these programing languages iOS/Swift and Android/Kotlin, in my app there is a chat messaging part that these users can use to send messages, the messages are Orderd by date in each device, there will be a date that is gotten from the devise calendar
so in Swift if I say
let date = Date() this date will be the date that's in the device
or in Kotlin
var date = Date()
those variables will give me their device dates so if the user in android sends a message and his clock was a little late his message will be on the top instead of being the last message that was sent and to make it more clear.
example
iPhone device clock is 7:44:33 hh:mm:ss & Android Device clock 7:44:55 hh:mm:ss
if the first message was sent is from the Android and then the iPhone replay to that message, messages should be ordered like this
android: Hi
iPhone: hello there
but instead of that the messages are ordered by the date and comparing the two dates that were given from the devices, the messages are ordered like this
iPhone: hello there
android: Hi
cause the iPhone calendar clock is too early, so my question is this how to get a one date for all the devices by the timezone or any other solution that is available like an international timestamp or something or an international date cause I only need these dates to order my messages nothing else.

Flutter display DateTime based on mobile device settings

I am looking for some guidance on using flutter and taking a UTC datetime from the DB and displaying that time based on mobile devices settings like locale, 24 versus 12 hour time, etc...
I have done dateformating in flutter without an issue, just hoping for some guidance to do it in this manner.
Thanks
I have found that if its for display of a UTC pulled from DB just use the DateTime.toLocal()
Then you can do the formatting on the datetime for other items.

Calculating time interval in iOS application

I am developing an iOS application for iPod Touch in which my application displays the server time always. I always sync the application time with server time whenever the application comes to foreground by making a web service call to the server. If there is a connectivity loss between my server and client for few hours I wont be able to sync the application time. I read iOS does not support running a timer when the application is in background other than few limited cases mentioned below:
Apps that play audible content to the user while in the background, such as a music player app
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Newsstand apps that need to download and process new content
Apps that receive regular updates from external accessories
So how can I keep track of application time? Whenever the user switches to my application he needs to look at the server time so I need to run a timer to update the last synced server time.
A combination of other answers, create a class in charge of obtaining the server time and maintaining the last time the application was synced to the server using a combination of NSDate* lastSync and applicationDidBecomeActive. For example:
-(void)applicationDidBecomeActive:(UIApplication*)application {
[ServerTimeSync sharedInstance] resync];
}
ServerTimeSync will maintain an NSDate* property with the last sync time (you'll want to convert what the server gives you to an NSDate*).
You can store the NSDate when the app goes into the background. When it resumes, get the current NSDate again, and add the difference to your stored server time.
You don't need a timer for this at all.
I would suggest that when you sync time with your server, you have it return its current UNIX timestamp. You can then do:
[[NSDate date] timeIntervalSince1970];
...to get the device's current UNIX timestamp. Then what you can do is store the difference between these two timestamps. This is the clock skew between the server time and the device time.
You can now compute the server's approximate time by taking the device's current UNIX timestamp and adding the clock skew to it. Adjust for time-zone when displaying it (if you want), and you're done. Whenever you sync time with the server, you can just refresh the stored clock skew value.
If you want to get fancy, you can also attempt to measure and take network latency into account when determining the clock skew.
This approach should work much better than trying to store the server's absolute timestamp and then track how much time has elapsed using a timer (or any other mechanism).

Getting system time in iPhone

I know that there is a method [NSDate date] which returns current date and time from iPhone clock. But if this clock time was changed manually it would rune my code.
Is there any opportunity to get world time, not current time from iPhone?
Yes, you can have correct current time by using ntp/sntp.
Following uris might help you to write your own implementation:
Simple NTP client for iOS : http://code.google.com/p/ios-ntp/
NSDate from time server: http://pathoneycutt.com/2010/12/nsdate-from-time-server/

Timezone calculation

How to find out the current time in different timezone in xcode for an iphone application?
Suppose i'm in India and i want to know the current time in USA how do i get the time then.
Thanks in advance
Joy
See Introduction to Date and Time Programming Guide for Cocoa.
There are built-in methods for handling timezones.