使用JavaScript从Date获取月份名称,但日期比实际日期提前15天

use*_*067 1 javascript date

如何在JavaScript中生成月份名称(例如:10月/ 10月),还可以操作它以使其比实际日期提前15天?

我找到了2个不错的脚本,但不能将2个组合在一起.

<html>
<head>
<title>Combine Date Values</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--

var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";

var current_date = new Date();
month_value = current_date.getMonth();
day_value = current_date.getDate();
year_value = current_date.getFullYear();

document.write("The current date is " + months[month_value] + " " +
day_value + ", " + year_value);

//-->
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

^^^^以上将显示当前日期^^^^

<script type="text/javascript"> 
Date.prototype.addDays = function(days) {
this.setDate(this.getDate()+days);
}

var d = new Date();
d.addDays(15);
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month++;
var curr_year = d.getFullYear();
document.write(curr_month + "/" + curr_date + "/" + curr_year);
</script>
Run Code Online (Sandbox Code Playgroud)

^^^^这将显示提前15天的日期^^^^

所以最终的结果应该是这样的. 示例1 实际日期:2013年5月28日显示日期:2013年6月12日

示例2 实际日期:2013年5月15日显示日期:2013年5月30日

示例3 实际日期:2013年5月16日显示日期:2013年6月1日

Cha*_*mal 6

以下是您要查找的样本,

var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";

var current_date = new Date();
current_date.setDate(current_date.getDate() + 15);
month_value = current_date.getMonth();
day_value = current_date.getDate();
year_value = current_date.getFullYear();

document.write("The current date is " + months[month_value] + " " + day_value + ", " + year_value);
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/UXy8V/1/