How can I fix iOS objective-c timezone issue? - ios

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.

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.
Store the date in UTC/GMT on server.
Get the date string in app, use NSDateFormatter with GMT/UTC as timezone to convert it to NSDate object in Objective-C
Use NSDateFormatter 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.
Here's apple's guide to managing timezones: Using Time Zones
A useful discussion here: A Fast, Accurate Way to Handle Dates from Servers

Please first convert your system's timezone to your server's timezone when you select date-time from database then send it to server.

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

Related

Where Ruby get date, time from?

I am working in ruby, I have an object containing today's date, time from DB and only want time truncating the date. I can get,
DateTime.now.strftime("%H:%M")
I'm curious about where Ruby get date and time from? From internet, device or browser?
https://ruby-doc.org/core-2.2.0/Time.html#method-c-new
Unless given a time during initialization of a Time instance, Ruby uses the type from the system it is running on.
If you want the current time on a user's device in a Rails project, you'll need to capture it with Javascript and pass it back to your Rails application.

What is the reference for Time.localtime

When using the localtime method on a UTC Time object, is the time returned the local time as specified in the app configuration or the local time of the user's location?
localtime will give you the time in the current time zone of the machine running the code.
Apidock(localtime): for ruby, ruby on rails
.localtime in your app will show your app's time. To display localtime to different users you will need to add some Javascript.
This answer might help you.
How to display the time in user's timezone

Change jenkins timestamp according to the browser timezone

I have a really simple question and couldn't find the answer about. Is it possible to change the jenkins timestamp according to the user's browser timezone. As my Jenkins server is in UTC but some of our users are in Central timezone while other are in few different timezones. So I want that they see the task(s) timestamp according to their browser time/timezone. How we can achieve this? Thanks
One possible approach for this could be to deliver all dates in a default timezone and use momentjs or a similar library to convert the date time on the frontend side to either the browsers timezone (this could be the default) or to a manually selected one.
This would be rather easy to implement and would not require any big changes in jenkins itself, just all places that deliver times must be wrapped in some markup, e.g. a class and some data-fields (e.g. data-datetime containing an rfc3339 timestamp)
Jenkins issues JENKINS-19887 and JENKINS-1962 detail potential fixes that could be introduced, though they haven't been implemented in any version of the system yet.
If you're only looking for timestamps with the browser's time zone in your console output (with all other timestamps unmodified), Timestamper provides this functionality.

Is the location services prompt needed for only timezone in ios

I can't seem to find if I need to have the location services prompt if I'm just using the timezone? I've turned off location services on my phone while testing and it still finds my timezone with it off. I just don't want to be rejected by apple.
I'm using this:
var timeZone = NSTimeZone.localTimeZone().name
Thanks for any help.
Keith
No. You will never get a prompt for localtimezone which is used by default when creating your NSDate objects. BTW you are not defining any timeZone like this you are only assigning the name of the local timezone to a var.
If you need some more info regarding time zones you should take a look at this link:
using NSTimeZone framework

MVC Handling Timezones and JSON Serialization - How to Convert to Specific Timezone

I've spent quite a bit of time on stackoverflow and the internet trying to determine what has been done in my situation. I am building a
centralized line of business website that could span multiple timezones. Based on some valuable information here I have a plan in place to handle this.
Timezone will be a part of a user profile
All Dates will be stored in UTC
EF sets DateTimeKind to UTC on retrieval from database
Is it possible to prevent EntityFramework 4 from overwriting customized properties?
Create some html helpers for DatePickers and DateDisplays to convert UTC time to local time (based off user timezone)
Use Model Binding to convert back to UTC on form posts.
Timezone Strategy
Now to the issue I don't know how to solve. Kendo UI uses JSON to pass information back and forth and as far as I can tell the JSON.net serializer cannot serialize a date to a specific time zone. I can serialize the date as UTC or have JSON.net automatically convert it to local time using the DateTimeZoneHandling setting but that would be local time on the server. From looking at the JSON.net code, I'm not sure I could even write a converter to do what I wanted. So far now if I send the date as UTC through JSON.net and Kendo automatically converts the time to the browser's local timezone.
Assuming User Profile timezone = Browser Timezone seems a little scary for me and I wanted to see what stackoverflow suggests I do. Thank you in advance.
Technology
ASP.net MVC 5
Entity Framework 6
Telerik Kendo UI Controls
JSON.net
Unfortunately I don't know many of the tools you are using, but I know how I would handle timezones.
I would use UTC everywhere, except when displaying times (or rather: datetimes) and in user input.
I would let the browser's JavaScript do the conversion in output, using the browser's timezone. In input, the conversion can be done either client side or server side. In the latter case the timezone must be part of the information sent from the browser to the server. The UTC timezone on the servers should be set at a level as low as possible, and, if possible, in all components (OS, web server, DB...).
A user's preferred timezone is nonetheless useful for all cases where the timezone is not known (e.g., in email communications - but remember to always have the timezone in time formats).
There are times (no pun intended...) when the above is not easy or does not apply. E.g., a schedule (calendar), to which the user attaches the timezone they have in their head, not necessarily the browser's one. Another case is when the user's timezone has to be known for some computation that can not easily be done on the browser - in this case the server will have to get the timezone from the browser first. But most of the time (still no pun intented...) you can happily do without timezones (with UTC) except immediately before showing something to the user or immediately after getting something from the user.
Regarding your last paragraph: you will very soon run into trouble if you assume "user profile timezone = browser timezone".
Some last words of advice:
"Timezone" is an ambiguous term. It may refer to a fixed offset from UTC (like UTC+1), or to the rules for calculating this offset for any instant in a given area (like the timezone of Rome, Italy). Always use the second meaning (e.g., don't use the current offset for a date in the future or past, but correctly convert datetimes back and forth), and remember that both can change during a user's session.
Be careful not to handle "pure" dates as the midnight of the same day (and not as noon either - people in Samoa will thank you), because then the date can change when the timezone changes. In other words, don't attach time information to pure dates.
P.S.: By following a link of yours, I was happy to find that I totally agree with the closing remark of this answer (by someone with more SO reputation than me)
You certainly can pass UTC to the browser and let it convert, but you have to be aware of the potential for inaccuracies. You also can convert server-side and pass a DateTimeOffset in your JSON, but you may need to render it yourself, using something like moment.js.
In the end, what you should do is entirely up to you. Many use cases are similar, but there are plenty of acceptable different paths depending on your exact needs.
Your question is very broad the way you have asked it. What parts are you most concerned with? Kendo? EF? JavaScript? Client-side time zone conversion? Formatting? Could you refine it or provide some context to the type of things your date/time values are representing? Otherwise, you may get some useful tidbits, but it will be hard to provide a definitive answer.
(Oh, and you might be interested in this.)
I was finally able to find this answer here https://stackoverflow.com/a/11968692/3412859 that will allow me to write my own JSONconverter and convert to a specific time zone before it is serialized. I now have all of the dates being converted on the server side based on the timezone setting in the user profile.
I had this problem , too.
It works for me.
I translated the time format to
Start=2016-4-9T8:30:00.000Z
End=2016-4-9T13:30:00.000Z
in background or database.
By doing this,local time zone is useful.

Resources