[英]I need to change date format from dd-MM-yyyy to yyyy-MM-DD
我想在日期格式进入数据库之前更改它。
我有一个日历。 我正在以dd-MM-yyyy
格式从前端发送日期。
当我以这种格式发送时: yyyy-MM-dd
一切正常。 但我需要dd-MM-yyyy
我正在使用 PostgreSQL 并且我有一个属性可以用时区格式将日期存储在时间戳中
例如:我在 DB 中的日期 2021-06-11 12:58:44.000000 +00:00
我的 rest controller
@PutMapping("/edit")
public void editTime(@RequestBody UserDto userDto) {
//userDto.getTime() - has this format dd-MM-yyyy
// I understand that i need to change format here. But i don't know how
LocalDate date = LocalDate.parse (userDto.getTime());
Instant currentTime = date.atStartOfDay(ZoneId.of("UTC")).toInstant();
userService.update(userDto.getId(),currentTime);
}
服务方式
public interface UserService {
User update(String Id, Instant time);
}
LocalDate date = LocalDate.parse (userDto.getTime(), DateTimeFormatter.ofPattern("dd-MM-yyyy"));
如果您以这种“dd-MM-yyyy”格式传递,希望这应该可以正常工作。
https://help.gooddata.com/cloudconnect/manual/date-and-time-format.html >> 这是 Java DateTimeFormatter
模式的好链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.