I want pass some Time value ( java.sql.Time) from back end to the front end in a Java EE project. For some historical reason, I parse the Time type to long type by call the method getTime(), which means I used long type to communicate between front end and back end. There comes the problem:
When I get long type time in the front end, I have to change the long type back to Time with the js method: new Date(long), but the value get from this method will diff from clients' timezone, which means different client in different timezone will see the result differently. This is absolutely not what I want. All the clients should see the same result, equals to the result in the back end.
Two ways to solve this:
Change the timezone of both front end and back end to UTC time, but java.sql.Time is timezone-independent, I have to change JVM timezone if I want to change the timezone of java.sql.Time. This is not a good way. Any other way to change the timezone?
Pass the timezone of back end to the front end. But change the timezone other than UTC in the front end is hard (may need some js lib).
Can anyone show me the best way to solve the problem?