The one that is configured under options --> date/time --> Time format.
The choices are 24 or 12 hour and I would like to avoid repeating this choice in my apps if possible.
If you use SimpleDateFormat with the DATE_SHORT, DATE_MEDIUM or DATE_LONG pattern, the formatter will do what is specified in the device settings.
Related
I have the following the scenario...
I want to set an alarm for myself on my mobile device for 30 days from today (at noon). I also want to do the same for a number of other people in a number of different timezones.
I DON'T want to convert 30 days at noon MY local time into whatever their local time is. (I'm on US Pacific time - I DON'T want US East Coast users to experience the alarm at 3PM.) Instead, I want those others to experience the alarm 30 days from now at noon THEIR local time.
So what is the best practice for storing this type of date/time information? Storing UTC doesn't make sense here. In these cases, do people typically just store the date and time in strings and then use those to generate local times on local machines?
Indeed, it sounds like you should keep track of simply the date and time that you want the event to fire, either with respect to the end-user's time zone - or perhaps without a time zone at all (to infer their local zone).
This has been covered before, several times such as here.
You didn't indicate what programming language or database environment you are using, but in general you shouldn't store date/time values as strings, but instead you should use a data type appropriate for the scenario you are in. Some of them may be UTC-based, but many are not.
I my app, I am reading time zone by
[[NSTimeZone] localizedName]
It works for most of the cases. However the iOS the one displayed is not necessarily the one read from settings. For example, if we set time zone to "Phoenix, U.S.A.", when we read it, it's "Mountain Standard Time".
The question is: Is there a way to get the display time zone name?
There is a [NSTimeZone isDaylightSavingTime] can be used to differentiate the 2 time zones.
Am developing website like online travel portal. The issue is displaying GMT time for various regions at flight booking and list out the timing. Any one gives idea to calculate and show the time for different countries?
Thanks
Although it is pretty hard to answer your question without a reference to particular technology, I will try.
End user Time Zone detection
Definitely, all time-related information should be presented both in local format and local time zone. By local I mean the one used by end user.
I am guessing that your application will not require creating user profiles. I am also assuming that flight schedules will not be visible on front page and user would need to perform search. In that case you have three choices:
Let user specify time zone from drop down box. I have no way to show you how it should be done without referring to concrete technology. The only thing I must point out is, it should present UTC offset, time zone name and list of cities, for example: UTC+01:00 Central European Time (Paris, Berlin, Warsaw).
You could read current time zone offset with JavaScript and send it out to server
In that case you can use following code snippet to detect offset:
var now = new Date();
var offset = now.getTimezoneOffset();
This will give you current GMT offset in minutes. The problem with that solution is, this offset might be different on the target date.
Obviously you could as well send GMT based dates in invariant form to the browser (for example using ISO8601 format: 2011-05-25T11:07Z) and format this date on the client using JavaScript. I never heard of for example JQuery plugin which would do that correctly (respecting local formats), though. It seems that you would be forced to write your own.
Date and time formatting as well as time zone conversion
Ha, it depends on solution you want to implement as well as technology you want to use. For now, I can't write much here.
I have worked for various web projects but correct date time localization have not been done and considered throroughly so I want to ask this very typical problem here and I want to hear comments from expert in this problem
What is the correct strategy for storing a date/time value from client from server
As I understand, because of locale and timezone so we have to do the conversion, I have heard about GMT or UTC time and after do some search it seems that UTC is more accurate ? so we will convert from client time -> UTC+0 when saving and when we read the value from server to client, we convert from server time back to client time again ?
However, I see in some website, at the bottom have the sentence "All times are in UTC", "All times are in GMT" and also "All times are in your local time". So maybe not all the sites do the convertion back and forth ? And in that case the user has to manually do the date/time conversion ?
How to display the date/time convenient to user based on his locale and region
How to provide personalization on date/time value ? I had one time depends on vbscript to do the display and the format is read from windows regional and format settings automatically. But without vbscript how can we determine a date/time pattern for a user of a specific locale. Do we have to store a mapping between a locale and pattern somewhere and do the conversion at the server side ?
Although date/time conversion is needed in most case, there's situation where only date matter for example if my birthday is 2 Feb 1980, it should be the same for all locale and no conversion should be done. How can we address this issue.
Storing the dates in UTC is always better. While displaying to user, convert it to local time and display
I have to write some code working with timezones. Is there a good introduction to the subject to get me started?
Also answered at What every developer should know about time (which includes the referenced screenshots).
With daylight savings time ending today, I thought this was a good time for a post. How to handle time is one of those tricky issues where it is all too easy to get it wrong. So let's dive in. (Note: We learned these lessons when implementing the scheduling system in Windward Reports.)
First off, using UTC (also known as Greenwich Mean Time) is many times not the correct solution. Yet many programmers think if they store everything that way, then they have it covered. (This mistake is why several years ago when Congress changed the start of DST in the U.S. you had to run a hotfix on Outlook for it to adjust reoccurring events.)
So let's start with the key question – what do we mean by time? When a user says they want something to run at 7:00 am, what do they mean? In most cases they mean 7:00 am where they are located – but not always. In some cases, to accurately compare say web server statistics, they want each "day" to end at the same time, unadjusted for DST. At the other end, someone who takes medicine at certain times of the day and has that set in their calendar, will want that to always be on local time so a 3:00pm event is not 3:00am when they have travelled half way around the world.
So we have three main use cases here (there are some others, but they can generally be handled by the following):
1.The same absolute (for lack of a better word) time.
2.The time in a given time zone, shifting when DST goes on/off (including double DST which occurs in some regions).
3.The local time.
The first is trivial to handle – you set it as UTC. By doing this every day of the year will have 24 hours. (Interesting note, UTC only matches the time in Greenwich during standard time. When it is DST there, Greenwich and UTC are not identical.)
The second requires storing a time and a time zone. However, the time zone is the geographical zone, not the present offset (offset is the difference with UTC). In other words, you store "Mountain Time," not "Mountain Standard Time" or "Mountain Daylight Savings Time." So 7:00 am in "Mountain Time" will be 7:00 am in Colorado regardless of the time of year.
The third is similar to the second in that it has a time zone called "Local Time." However, it requires knowing what time zone it is in in order to determine when it occurs.
Outlook now has a means to handle this. Click the Time Zones button:
And you can now set the time zone for each event:
When I have business trips I use this including my flight times departing in one zone and arriving in another. Outlook displays everything in the local timezone and adjusts when that changes. The iPhone on the other hand has no idea this is going on and has everything off when I'm on a trip that is in another timezone (and when you live in Colorado, almost every trip is to another timezone).
Putting it to use
Ok, so how do you handle this? It's actually pretty simple. Every time needs to be stored one of two ways:
1.As UTC. Generally when stored as UTC, you will still set/display it in local time.
2.As a datetime plus a geographical timezone (which can be "local time").
Now the trick is knowing which to use. Here are some general rules. You will need to figure this out for additional use cases, but most do fall in to these categories.
1.When something happened – UTC. This is a singular event and regardless of how the user wants it displayed, when it occurred is unchangeable.
2.When the user selects a timezone of UTC – UTC.
3.An event in the future where the user wants it to occur in a timezone – datetime plus a timezone. Now it might be safe to use UTC if it will occur in the next several months (changing timezones generally have that much warning - although sometimes it's just 8 days), but at some point out you need to do this, so you should do it for all cases. In this case you display what you stored.
4.For a scheduled event, when it will next happen – UTC. This is a performance requirement where you want to be able to get all "next events" where their runtime is before now. Much faster to search against dates than recalculate each one. However, this does need to recalculate all scheduled events regularly in case the rules have changed for an event that runs every quarter.
1.For events that are on "local time" the recalculation should occur anytime the user's timezone changes. And if an event is skipped in the change, it needs to occur immediately.
.NET DateTime
Diving in to .NET, this means we need to be able to get two things which the standard library does not provide:
1.Create a DateTime in any timezone (DateTime only supports your local timezone and UTC).
2.For a given Date, Time, and geographical timezone, get the UTC time. This needs to adjust based on the DST rules for that zone on that date.
Fortunately there's a solution to this. We have open sourced out extensions to the DateTime timezone functionality. You can download WindwardTimeZone here. This uses registry settings in Windows to perform all calculations for each zone and therefore should remain up to date.
Browser pain
The one thing we have not figured out is how to know a user's location if they are using a browser to hit our web application. For most countries the locale can be used to determine the timezone – but not for the U.S. (6 zones), Canada, or Russia (11 zones). So you have to ask a user to set their timezone – and to change it when they travel. If anyone knows of a solution to this, please let me know.
Update: I received the following from Justin Bonnar (thank you):
document.getElementById('timezone_offset').value = new Date().getTimezoneOffset();
Using that plus the suggestion of the geo location for the IP address mentioned below will get you close. But it's not 100%. The time offset does not tell you if you for example if you are in Arizona (they & Hawaii do not observer daylight savings time) vs Pacific/Mountain (depending on DST) time zone. You also depend on javascript being on although that is true for 99% of the users out there today.
The geo location based on IP address is also iffy. I was at a hotel in D.C. when I got a report of our demo download form having a problem. We pre-populate the form with city, state, & country based on the geo of the IP address. It said I was in Cleveland, OH. So again, usually right but not always.
My take is we can use the offset, and for cases where there are multiple timezones with that offset (on that given day), follow up with the geo of the IP address. But I sure wish the powers that be would add a tz= to the header info sent with an HTML request.