I am using Joda-Time API for managing date and time in my web application.
I have a method which converts the milliseconds to Calendar
object.
public static synchronized Calendar getUTCCalenderInstance( final Long millisecondsTime )
{
return new DateTime(millisecondsTime).withZone(DateTimeZone.UTC).toGregorianCalendar();
}
And I am saving it in MySQL database using spring-data-jpa
. But when viewed in database, it is storing the timestamp in current local timezone. How to fix this issue?
My application.properties
:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/my_db?
useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false
My Java entity is:
@Entity
@Table( name = "task" )
@Data
public class TaskModel {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
@Column( name = "t_id" )
private Long id;
@Column( name = "t_name" )
private String taskName;
@Column( name = "t_description" )
private String taskDescription;
@Column( name = "t_start_date" )
private Calendar startDate;
@Column( name = "t_due_date" )
private Calendar dueDate;
@Column( name = "t_created_at" )
private Calendar createdAt;