pmsguy
asked on
How do I set the Timezone for a Java Application dynamically like PHP date_default_timezone_set?
PHP allows you to set the timezone for the session using date_default_timezone_set.
I want to do the same for my Java application. That is, dynamically change the timezone for the session. The timezone needs to dynamically change multiple times during the Java session.
I do NOT want to set the timezone for every instance of a date/time related object.
Also, I do not want to use a command line setting like "java -Duser.timezone=UTC"
I want to do the same for my Java application. That is, dynamically change the timezone for the session. The timezone needs to dynamically change multiple times during the Java session.
I do NOT want to set the timezone for every instance of a date/time related object.
Also, I do not want to use a command line setting like "java -Duser.timezone=UTC"
Your app should be set up to store and use the timezone of the client
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Generally speaking, you will ask the user to set their timezone as a preference and then save it always in a cookie. otoh, you could do it for the session only
ASKER
My java process is a daemon process and I need to dynamically change the timezone for the given database I am traversing. Therefore, I want to change the timezone in Java so any date/time command will be relative to this timezone. Again, I am asking is there a command in Java to set the default timezone for the session? Similar to PHP; see http://php.net/manual/en/function.date-default-timezone-set.php
>>Again, I am asking is there a command in Java to set the default timezone for the session?
No - you need to do that yourself
No - you need to do that yourself
ASKER
Please exlain - "how to do that yourself?"
That would depend on how you want this custom timezone to manifest itself
> Again, I am asking is there a command in Java to set the default timezone for the session?
I already mentioned above that there isn't
I already mentioned above that there isn't
session.setAttribute("my.t
ASKER
So for every data/time command I instantiate in Java I have to set the timezone?
That stinks if that is the case.
Again, php allows you to define the timezone for the application, see http://php.net/manual/en/function.date-default-timezone-set.php.
I can't see how Java does not allow you to do this.
That stinks if that is the case.
Again, php allows you to define the timezone for the application, see http://php.net/manual/en/function.date-default-timezone-set.php.
I can't see how Java does not allow you to do this.
>>So for every data/time command I instantiate in Java I have to set the timezone?
No - you just get and use the TimeZone you saved in the session
No - you just get and use the TimeZone you saved in the session
Why not make all of it UTC? Then the only time you would need to be concerned about the local time zone is when you are ready to produce client output.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.