I am writing a spring boot application using Thymeleaf as template engine.
The issue is I am getting UTC server time displayed on UI instead of client time (GMT +3):
Actual result: 10-May-2021 19:20:30
Expected result: 10-May-2021 22:20:30
I found a solution using javascript here: Convert UTC date time to local date time
in header:
<script type="text/javascript">
function localize(t)
{
var d=new Date(t+" UTC");
document.write(d.toString());
document.write(d.toString().replace(/GMT.*/g,""));
}
</script>
in body:
<script type="text/javascript">localize("6/29/2011 4:52:48 PM");</script>
and it works..
however, I do not know how to incorporate this code into my Thymeleaf template:
<table class="table table-bordered table-striped ">
<thead class="thead-dark">
<tr>
...
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="tempReport : ${page}">
...
<td th:text="${#dates.format(tempReport.createdAt, 'dd-MMMM-yyyy HH:mm:ss')}"></td>
</tr>
</tbody>
</table>
Any help to incorporate the javascript code into Thymeleaf template will be appreciated! Any other approaches to convert the time are welcome as well!