Search code examples
javatimezonelocaltime

How to set the necessary timezone in LocalTime


I have a database which has a movie schedule. Well, of course there are two such columns:

CREATE TABLE tableName (
    hall_movies_schedules_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    hall_id  BIGINT UNSIGNED NOT NULL,
    film_id  BIGINT UNSIGNED NOT NULL,
    start_at TIME   NOT NULL,
    end_at   TIME   NOT NULL,
    date     DATE   NOT NULL,
    cost     INT    UNSIGNED NOT NULL,
    FOREIGN KEY(hall_id) REFERENCES cinema_halls(hall_id),
    FOREIGN KEY(film_id) REFERENCES films(film_id),
    PRIMARY KEY (hall_movies_schedules_id)
);  

I have entity in java code:

@Entity
@Table(name="tableName")
public class HallMoviesSchedule {

    ...
    @Column(nullable = false, name = "start_at")
    @DateTimeFormat(iso = DateTimeFormat.ISO.TIME)
    private LocalTime startAt;

    @Column(nullable = false, name = "end_at")
    @DateTimeFormat(iso = DateTimeFormat.ISO.TIME)
    private LocalTime endAt;
    ...

}

But pulling information to my web page gives one hour less than is in the database for my region. How can this be fixed?


Solution

  • LocalTime does not have TimeZone. You have to use ZonedDateTime instead.