Java. Creating a date according to user timezone in web-application
I have a Java web-application. In some places there is showing of dates. I want to display the date according to user timezone. How do I create a date for the show if I know the timezone the user? I use the class Date. Any help would be greatly appr开发者_如何学JAVAeciated.
There is no standard way to do this. On client side, you may capture time using Java script and send that information to the server. On server side, you can covert the time to Coordinated Universal Time.
Use GregorianCalendar rather than Date when you have any requirements besides basic display. You can create one for the current time by time-zone using new GregorianCalendar(TimeZone)
.
精彩评论