SimpleDateFormat.format(currentDate)不会更改currentDate变量[duplicate]

问题描述 投票:-3回答:1

当我在servlet中进行类似的操作时,我仍然会获得Sun Jun 07 00:59:46 CEST 2020之类的日期格式,但我想使其像2020.06.07之类的方式>

我的servlet中的代码:

SimpleDateFormat sdfo = new SimpleDateFormat("yyyy-MM-dd");
Date currentDate = new Date();
sdfo.format(currentDate);
request.setAttribute("currentDate", currentDate);

还有我的jsp文件:

Current date: <c:out value="${currentDate}"/>

我应该在这里更改什么?

[当我在servlet中进行类似这样的操作时,我仍在获取日期格式,如Sun Jun 07 00:59:46 CEST 2020,但我想使其成为2020.06.07在我的servlet中的代码:SimpleDateFormat sdfo = new ...] >

java date simpledateformat
1个回答
2
投票

您已将currentDate而不是格式化的日期字符串设置为request

替换

© www.soinside.com 2019 - 2024. All rights reserved.