0

I am listing a table that is stored in a MySQL BBDD and I don't know why the DateTime field is showing with +1 hour when printed in the Thymeleaf view.

This is the code of the table where I retrieve the info:

    <a th:href="@{/new}">Agreagar Nuevo</a>
        <table border="1">
            <thead style="background-color: #5BA5EA">
                <tr>
                    <th>Nombre</th>
                    <th>Apellidos</th>
                    <th>Tlf.</th>                   
                    <th>Tratamiento</th>
                    <th>Doctor</th>
                    <th>Cita</th>
                    <th>Acción</th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="p:${lista_pacientes}">
                    <td th:text="${p.nombre_pac}"></td>
                    <td th:text="${p.apellidos_pac}"></td>
                    <td th:text="${p.tlf_pac}"></td>
                    <td th:text="${p.tratamiento_pac}"></td>
                    <td th:text="${p.doctor_pac}"></td>
                    <td th:text="${#dates.format(p.cita_pac, 'EEEEE, dd/MMMMM/yyyy - HH:mm')}"> </td>
                    <td>
                    <a th:onclick="eliminar([[${p.id_pac}]])" href="#">Borrar</a>
                    <a th:href="@{/listar/}+${p.id_pac}">Modificar</a>
                    </td>
                </tr>
            </tbody>
        </table>

And here you can see how that database record is stored in MySql and how the filed date is being printed in the view with +1 hour:

Stored Date in MySQL vs printed Date

I have tried to change the time zone in MySQL to many different values but it didn't work: SET time_zone = "+00:00";

Thanks

HOTOMOL
  • 71
  • 6
  • MySQL & jdbc connector version? – ProDec Nov 14 '21 at 11:37
  • I don't know specifically how to check the "MySQL & JDBC connector version". These are the dependencies of JPA and MySQL I added to my pom.xml: spring-boot-starter-data-jpa mysql-connector-java – HOTOMOL Nov 14 '21 at 11:43
  • And these are the appliation.properties related to JDBC and MySQL drivers: spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect – HOTOMOL Nov 14 '21 at 11:46
  • You need to set your timezone. you can check similar question here https://stackoverflow.com/questions/32150292/mysql-now-is-1-hour-behind – Hassan Liasu Nov 14 '21 at 11:50
  • there is different default behavior to session time zone for jdbc connector since 8.0.23 compared to previous version – ProDec Nov 14 '21 at 11:57

1 Answers1

0

Just in case this post can help anyone else: I have solved it by deleting the parameter ?serverTimezone=UTC when linking the database in the application.properties file:

enter image description here

HOTOMOL
  • 71
  • 6