我正在尝试保存日期和时间,以使其从用户在JSP中创建并由Java servlet接收的前端通过用户。以下是我的JSP的代码:
<form role="form" action="/abc" method="post">
<div class="form-group">
<div class="input-group">
<input type="hidden" name="div_bvg" type="number" class="form-control" value="0" required/>
</div>
</div>
Enter the Details:
<div class="input-group">
<span class="input-group-addon">End Date</span>
<input name="div_enddate" type="datetime-local" class="form-control" required/>
</div>
</div>
<a href="/dashboard" class="btn btn-default">Cancel</a>
<button type="submit" class="btn btn-success">Save</button>
</form>
以下是通过我的servlet进行的接收
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
String sdate = request.getParameter("div_enddate").trim();
DateTime enddate = new DateTime(edate);
Entity election = new Entity("example");
election.setProperty("EndTime", enddate);
Transaction txn = datastore.beginTransaction();
datastore.put(txn,election);
txn.commit();
if (txn.isActive()) { //if trnasaction is still active (which means not committed properly then it rollbacks)
txn.rollback();
}
以下是我提交时遇到的错误
java.lang.NumberFormatException: Invalid date/time format: 2020-01-01T01:00
我不清楚您打算如何在前端花费时间,但是您正在将无效的时间格式传递给Java。