将日期设定为10天,格式为dd / mm / yyyy(例如21/08/2010) [英] Set date 10 days in the future and format to dd/mm/yyyy (e.g. 21/08/2010)

查看:292
本文介绍了将日期设定为10天,格式为dd / mm / yyyy(例如21/08/2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很感激帮助创建一些最终会在Selenium中使用的JavaScript,它会在当前日期提前10天自动设置日期,并以下列格式显示dd / mm / yyyy。

I would really appreciate some help creating some JavaScript that will eventually be used in Selenium that automatically sets a date 10 days ahead from the current date and displays in the following format dd/mm/yyyy.

我目前有以下脚本,但我没有随处获得:

I currently have the script below, but I'm not getting anywhere with it :

var myDate=new Date();
myDate.now.format(myDate.setDate(myDate.getDate()+5),("dd/mm/yyyy");

我们非常感谢任何帮助。

Any help would be much appreciated.

推荐答案

这是一个获得的例子未来日期......

Here is an example of getting the future date...

var targetDate = new Date();
targetDate.setDate(targetDate.getDate() + 10);

// So you can see the date we have created
alert(targetDate);

var dd = targetDate.getDate();
var mm = targetDate.getMonth() + 1; // 0 is January, so we must add 1
var yyyy = targetDate.getFullYear();

var dateString = dd + "/" + mm + "/" + yyyy;

// So you can see the output
alert(dateString);

有一些更优雅的方式来格式化日期,例子可以在以下目的地找到:

There are some more graceful ways to format dates, examples can be found at the following destinations:

http://www.west-wind.com/Weblog/posts/282495的.aspx

http://www.svendtofte .com / javascript / javascript-date-string-formatting /

这篇关于将日期设定为10天,格式为dd / mm / yyyy(例如21/08/2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆