[英]How to compare the datetime of format "EEE MMM dd HH:mm:ss zzz yyyy" and "yyyy-MM-dd hh:mm:sss" in java?
[英]Spring - LocalDateTime - how to return just the hours and minutes instead of dd-mm-yyyy hh-MM-ss-sss
我的数据库中的“锻炼”表中有一个名为 starttime 的列,我正在尝试使用 LocalDateTime 将开始时间保存到该列。 在我的锻炼 class 中,我输入了以下内容:
@JsonFormat(pattern="HH:mm")
@Column(name = "starttime")
private LocalDateTime startTime;
然后我试图在我的数据加载器中保存一个 testWorkout,如下所示:
Workout testWorkout = new Workout(LocalDateTime.now(), 88.00);
workoutRepository.save(testWorkout);
当我运行我的应用程序并签入 postgresql / postico 时,我看到开始时间为:2022-02-01 12:53:26.488
我如何让它只记录小时和分钟?
我对此很陌生,因此将不胜感激。
谢谢
https://www.postgresql.org/docs/current/datatype-datetime.html
Table 8.14. Date/Time Output Styles
Style Specification Description Example
ISO ISO 8601, SQL standard 1997-12-17 07:37:16-08
SQL traditional style 12/17/1997 07:37:16.00 PST
Postgres original style Wed Dec 17 07:37:16 1997 PST
German regional style 17.12.1997 07:37:16.00 PST
从这个图表,这意味着,数据库查询 output 不能将时间返回为“HH-MM”。 因此,您需要将其格式化为 char/text 类型。 24小时类型:
select to_char(localtime(0),'HH24:MI');
12小时型
select to_char(localtime(0),'HH12:MI');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.