&l..._js 当前日期的365天">
赞
踩
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
body{text-align:center}
</style>
<script type="text/javascript">
//设置所有url;
function setallurl(){
//调用日期js
var infoTime = getNowDate();
//当前时间
var endTime = infoTime["endTime"];
//当前时间-前一个月
var startTime = infoTime["startTime"];
document.getElementById("endTime").value=endTime;
document.getElementById("startTime").value=startTime;
}
//日期获取
function getNowDate() {
var sign1 = "-";
var sign2 = ":";
//当前日期
var date = new Date();
var nowYear = date.getFullYear() // 年
var nowMonth = date.getMonth() + 1; // 月
var nowDay = date.getDate(); // 日
var nowHour = date.getHours(); // 时
var nowMinutes = date.getMinutes(); // 分
var nowSeconds = date.getSeconds() // 秒
// 给一位数数据前面补加“0”
if (nowMonth < 10) {
nowMonth = "0" + nowMonth;
}
if (nowDay < 10) {
nowDay = "0" + nowDay;
}
if (nowHour < 10) {
nowHour = "0" + nowHour;
}
if (nowMinutes < 10) {
nowMinutes = "0" + nowMinutes;
}
if (nowSeconds < 10) {
nowSeconds = "0" + nowSeconds;
}
//前10天
var pastTime = new Date(date - 1000 * 60 * 60 * 24 * 10);//最后“10”数字根据需求修改,代表10天
//var pastTime = new Date(date + 1000 * 60 * 60 * 24 * 10);//“+”表示当前日期后“10”天
var pastYear = pastTime.getFullYear() // 年
var pastMonth = pastTime.getMonth() + 1; // 月
var pastDay = pastTime.getDate(); // 日
var pastHour = pastTime.getHours(); // 时
var pastMinutes = pastTime.getMinutes(); // 分
var pastSeconds = pastTime.getSeconds() // 秒
// 给一位数数据前面补加“0”
if (pastMonth < 10) {
pastMonth = "0" + pastMonth;
}
if (pastDay < 10) {
pastDay = "0" + pastDay;
}
if (pastHour < 10) {
pastHour = "0" + pastHour;
}
if (pastMinutes < 10) {
pastMinutes = "0" + pastMinutes;
}
if (pastSeconds < 10) {
pastSeconds = "0" + pastSeconds;
}
//当前日期
var endTime = nowYear + sign1 + nowMonth + sign1 + nowDay + " " + nowHour + sign2 + nowMinutes + sign2 + nowSeconds;
//前一个月日期
var startTime = pastYear + sign1 + pastMonth + sign1 + pastDay + " " + pastHour + sign2 + pastMinutes + sign2 + pastSeconds;
var infoTime = {"startTime":startTime,"endTime":endTime};
return infoTime;
}
</script>
</head>
<body οnlοad="setallurl()">
前一个月:<input id="startTime" type="text" value="" /></br>
当前日期:<input id="endTime" type="text" value="" />
</body>
</html>
结果展示:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。