[英]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.