follow this question: how to use utc in postgres timestamp with jdbc PrepareStatement parameter?
now i use
new java.sql.Timestamp(date.getTime() + date.getTimezoneOffset() * 60000)
to upload date value, and
tstmp.getTime() - tstmp.getTimezoneOffset() * 60000
to download value from postgres.
but, date.getTime() is milliseconds from 1970-01-01 of UTC timezone, it's static and not related to client timezone, see below
new Date(1443145546920)
Fri Sep 25 2015 09:45:46 GMT+0800 (中国标准时间)
*Now i change timezone from Beijing/Shanghai to Tokyo*
new Date(1443145546920)
Fri Sep 25 2015 10:45:46 GMT+0900 (Japan Standard Time)
look, 1443145546920 should always be Fri Sep 25 2015 01:45:46 +0000, never change whatever my client TimeZone is.
so, the right way should is:
client(utc+8) dbserver(utc)
upload time 1443145546920 without tzoffset
write 1443145546920
download
send 1443145546920
got 1443145546920 and add client tzoffset 480m
but postgres jdbc show me this way:
client(utc+8) jdbc of pg dbserver(utc)
upload time 1443145546920 + tzoffset
- tzoffset 480m
write 1443145546920
download
send 1443145546920
+ tzoffset 480m
got 1443145546920 + tzoffset
manual substract tzoffset