所以我有这个支付历史数据库,它的属性之一是时间戳类型(:MM:SS)。我需要做表格,以增加新的付款历史。我的控制器将自动捕获支付历史对象并将其添加到DB中。但由于我的时间格式在HTML (我选择日期时间-本地)不匹配的时间格式在DB,我不能继续添加我的新支付历史。
以下是我的错误:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments []; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]有没有可能在我的DB中创建格式准确的HTML输入,比如时间戳?谢谢!!
发布于 2018-11-21 12:55:40
您可以使用java.text.SimpleDateFormat更改日期时间格式。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"),
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parse = sdf.parse("2019-02-03T15:02".replace("T", " "));
String dateTime = sdf2.format(parse);
System.out.println(dateTime);输出
2019-02-03 15:02:00阅读更多关于日期和时间模式的信息。
https://stackoverflow.com/questions/53412326
复制相似问题