Per-user TimeZones in a webapp using Spring
I have a web application which has different users logging in to view transactions. I want to be able to let the users set their own time zone and then have dates on forms be bound using the user's timezone so that they can search transactions in a database and have the resul开发者_C百科ts adjusted depending on what time zone the user is in. IE I have a user in the mountain time zone searching between 8 am and 8 pm MDT, and I want them to be able to see transactions created between 8 am and 8 pm MDT. I also have another user searching in the eastern time zone who wants to search for transactions between 8 am and 8 pm, and I want their search to return results for transactions created between 8 am EDT and 8 pm EDT. I've tried having the editors resolved from the application using a custom FactoryBean that pulls the currently authenticated user and sets their TimeZone as the timezone used by the DateFormat used by Spring's editors, and this works initially, but by the time the calendars I'm using make it through Spring's binding system, the TimeZone is wiped out and replaced with (apparently) the system default. Has anybody ever implemented this sort of thing before ? It seems like nothing short of an epic pain in the butt.
I cannot help you on your specific implementation problems but i feel that the general idea of implementing timezones is not ideal.
You should use UTC timestamps in your server and let the client display it in the timezone the client system is using. This should be the general concept to follow here.
精彩评论