如何用数学计算显示未来的日期和时间
How to display future date and time with a math calculation?
我使用Jsp。我想根据当前日期和时间显示未来的日期和时间。
解释。客户在网站上购买商品,并在confirmation page
上看到他们订购的日期。我使用<input class="input_ship" style="border:none; background:papayawhip; text-align:center;" name="OrderDate" value="<%= new java.util.Date()%>" readonly>
向用户显示当前日期。
现在我想让用户知道他的订单什么时候会发货,通过做一个简单的数学方程(current date + X days later
)将返回未来的某个日期。我该如何做这个后端呢?
将日期值转换为Date
,如:
var currentdate = new Date(document.querySelector('input.input_ship').value);
现在你可以设置日期提前5天使用:
currentdate.setDate(currentdate.getDate()+5)
在java中可以这样做:
首先必须将输入值转换为Date
。
Date specifiedDate = new SimpleDateFormat("dd.MM.yyyy").parse("YourInputValueHere"); //You can change your format pattern for your input.
为指定日期添加天数,我们使用java.util.Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(specifiedDate);
calendar.add(Calendar.DATE, 2); //This method added 2 days to specified date.If you want subtract day from specified date you can do this calendar.add(Calendar.DATE, -2);
Date newDate = calendar.getTime();
相关文章:
- 更改angularjs中的日期-时间格式
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 将日期时间从json转换为可读格式
- 使用时刻.js从日期时间中提取时间
- 两个日期时间选择器
- Javascript:如何在onChange事件期间更改日期时间值
- .Net webApi ISO日期时间和IE8
- Javascript-如何使用bootstrap日期时间选择器自动计算两个时间输入之间的差异
- 转换日期时间格式
- 在JavaScript中转换日期/时间格式
- JavaScript JSON关联对象键和值都作为日期时间戳
- 将日期时间javascript绑定到表列
- 将JS日期解析为C#日期时间
- 使用JavaScript将客户端日期/时间字符串转换为JSON日期/时间串
- 从javascript数组获取php的日期时间
- 格式化momentjs日期时间
- 这个正则表达式的日期/时间有什么问题
- Mongoose查询在两个日期时间之间提取数据
- 当转换为Python日期时间时,Node的时间戳落后3分钟
- 自定义angularjs过滤器日期时间格式额外字符