LocalDateTime in advance two hours when submitting Form
When I'm going to submit a form with the Class LocalDateTime managing the time and date fields, it takes two hours. I found this advance with the time of my computer.
Code:
package com.algaworks.brewer.service;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.algaworks.brewer.model.Venda;
import com.algaworks.brewer.repository.Vendas;
@Service
public class CadastroVendaService {
@Autowired
private Vendas vendas;
@Transactional
public void salvar(Venda venda) {
if (venda.isNova()) {
venda.setDataCriacao(LocalDateTime.now());
}
if (venda.getDataEntrega() != null) {
venda.setDataHoraEntrega(LocalDateTime.of(venda.getDataEntrega(),
venda.getHorarioEntrega() != null ? venda.getHorarioEntrega() : LocalTime.now()));
}
vendas.save(venda);
}
}
1
Author: Valdeir Psr, 2019-01-19