[英]I need to change date format from dd-MM-yyyy to yyyy-MM-DD
I want to change the date format before it goes to the database.我想在日期格式进入数据库之前更改它。
I have a calendar.我有一个日历。 And I am sending date from frontend in dd-MM-yyyy
format.我正在以dd-MM-yyyy
格式从前端发送日期。
When I send with this format: yyyy-MM-dd
everything works well.当我以这种格式发送时: yyyy-MM-dd
一切正常。 But I need dd-MM-yyyy
但我需要dd-MM-yyyy
I am using PostgreSQL and I have an attribute to store the date in timestamp with time zone format我正在使用 PostgreSQL 并且我有一个属性可以用时区格式将日期存储在时间戳中
For example: my date in DB 2021-06-11 12:58:44.000000 +00:00例如:我在 DB 中的日期 2021-06-11 12:58:44.000000 +00:00
My rest controller我的 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);
}
Service method服务方式
public interface UserService {
User update(String Id, Instant time);
}
LocalDate date = LocalDate.parse (userDto.getTime(), DateTimeFormatter.ofPattern("dd-MM-yyyy"));
Hopefully this should work fine if you are passing in this "dd-MM-yyyy" format.如果您以这种“dd-MM-yyyy”格式传递,希望这应该可以正常工作。
https://help.gooddata.com/cloudconnect/manual/date-and-time-format.html >> this is a good link for Java DateTimeFormatter
patterns. https://help.gooddata.com/cloudconnect/manual/date-and-time-format.html >> 这是 Java DateTimeFormatter
模式的好链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.