I have this weird problem, when I create a calendar with a locale, the TimeZone just reverts to the local one
public void start(Locale locale){ String s = locale.getDisplayName(); System.err.println(s); Calendar c = new GregorianCalendar(locale); System.err.println(c.getTimeZone()); }
And this is the output:
español (Argentina) sun.util.calendar.ZoneInfo[id="Europe/Bucharest", //etc more useless date here....
How can i get the proper time from a specific locale ?
The short answer: you can't. The long answer: There is no such thing as "proper time zone for a locale". That's just because there are a few countries that have more than one time zone (for example United States). Time zone is a different concept.
CURRENT_TIMESTAMP returns the current date and time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE . The time zone offset reflects the current local time of the SQL session. If you omit precision, then the default is 6.
You can get the current time in a particular timezone by using the datetime module with another module called pytz . You can then check for all available timezones with the snippet below: from datetime import datetime import pytz zones = pytz. all_timezones print(zones) # Output: all timezones of the world.
match(/\(([^\)]+)\)$/)[1]; console. log("timezone", timezone); Now if you want to get the abbreviations or short forms of the timezone like IST, GMT, etc. then just pick the first letter of a string in the timezone.
The short answer: you can't.
The long answer: There is no such thing as "proper time zone for a locale". That's just because there are a few countries that have more than one time zone (for example United States). Time zone is a different concept.
Anyway, you are looking to solve your problem. I am guessing that you are writing a web application and you see that the time zone is reverting to the server default. That's a typical situation. Both Locale.getDefault()
and TimeZone.getDefault()
will return server-related information. The JVM has no way of knowing the "proper" time zone. So what can you do about it?
DateFormat
instance and it will convert time zone automatically.Out of these three possible choices, I always opt for number 1. By putting time zone information to user profile, you know for sure what his/her preferred time zone is, regardless of their current web browser, etc. Please keep in mind that some users might want to use your application while visiting other countries...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With