查看完整版本 : Java Date and timezone problem

linuxfedora 2018-12-13 03:22 PM

Java Date and timezone problem

I have java server program which will have a client to send their UTC time in string to me,
for example. if the client is in timezone UTC+8, if HK time is 2018-12-12 08:00:00, then it will send the string "2018-12-12 00:00:00" to the server program.

If the server is in timezone UTC+10 and i want to use Java Date to store their client date, how should i do it, and after store Date is stored in UTC time and later i want to convert to UTC date string like "2018-12-12 00:00:00", then what should i do?

When i write                
Date date = new GregorianCalendar(2018, 12, 12, 08, 00, 00).getTime();
the date seems to be in UTC+10, not a UTC 0 time?


Thanks

Ob1Kenobi 2018-12-14 07:59 AM

[quote]原帖由 [i]linuxfedora[/i] 於 2018-12-13 03:22 PM 發表 [url=https://computer.discuss.com.hk/redirect.php?goto=findpost&pid=491937527&ptid=27909291][img]https://computer.discuss.com.hk/images/common/back.gif[/img][/url]
I have java server program which will have a client to send their UTC time in string to me,
for example. if the client is in timezone UTC+8, if HK time is 2018-12-12 08:00:00, then it will send the s ... [/quote]
sending / receiving BOTH date & time zone object/string.:loveliness:

form5 2018-12-16 12:43 AM

Utc datetime string 不嬲都可以加time zone utc offset 

https://en.m.wikipedia.org/wiki/ISO_8601

form5 2018-12-16 12:58 AM

Java 有Joda time library, 
C# 有 Noda time library,搞埋 夏令,東令時間
頁: [1]
查看完整版本: Java Date and timezone problem