How to store a java.util.Date into a MySQL timestamp field in the UTC/GMT timezone?

后端 未结 5 1152
悲&欢浪女
悲&欢浪女 2020-12-24 03:35

I used a new Date() object to fill a field in a MySQL DB, but the actual value stored in that field is in my local timezone.

How can I configure MySQL to store it in

5条回答
  •  Happy的楠姐
    2020-12-24 04:14

    A java Date is timezone agnostic. It ALWAYS represents a date in GMD(UTC) in milliseconds from the Epoch.

    The ONLY time that a timezone is relevant is when you are emitting a date as a string or parsing a data string into a date object.

提交回复
热议问题