
已测试成功
<html>
<input type="text" id="prev">
<input type="text" id="now">
<input type="text" id="next">
</html>
<script type="text/javascript">
windowonload = function(){
getYear();
};
function getYear(){
function getEle(id){
return documentgetElementById(id);
}
var inputPrev = getEle("prev"),
inputNow = getEle("now"),
inputNext = getEle("next"),
d = new Date(),
nowYear = +dgetFullYear();
inputNow = nowYear;
inputPrevvalue = nowYear - 1;
inputNextvalue = nowYear + 1;
}
</script>
系统时间一般是值服务端时间,js获取服务端时间的方法是直接用ajax获取。
1、编写显示时间的页面:
<html>
<head>
<meta >
1、使用new Date()获取当前日期,new Date()getTime()获取当前毫秒数
2、计算公式,等于获取的当前日期减去或者加上一天的毫秒数。一天的毫秒数的计算公式:24小时60分钟60秒1000毫秒,也是86400000毫秒。
举例:
Date curDate = new Date();
var preDate = new Date(curDategetTime() - 2460601000); //前一天
var nextDate = new Date(curDategetTime() + 2460601000); //后一天
以下使用后台输出表示。
扩展资料
var myDate = new Date();
myDategetYear(); //获取当前年份(2位)
myDategetFullYear(); //获取完整的年份(4位,1970-)
myDategetMonth(); //获取当前月份(0-11,0代表1月)
myDategetDate(); //获取当前日(1-31)
myDategetDay(); //获取当前星期X(0-6,0代表星期天)
myDategetTime(); //获取当前时间(从197011开始的毫秒数)
myDategetHours(); //获取当前小时数(0-23)
myDategetMinutes(); //获取当前分钟数(0-59)
myDategetSeconds(); //获取当前秒数(0-59)
myDategetMilliseconds(); //获取当前毫秒数(0-999)
myDatetoLocaleDateString(); //获取当前日期
var mytime=myDatetoLocaleTimeString(); //获取当前时间
myDatetoLocaleString( ); //获取日期与时间
DateprototypeisLeapYear 判断闰年
DateprototypeFormat 日期格式化
DateprototypeDateAdd 日期计算
DateprototypeDateDiff 比较日期差
DateprototypetoString 日期转字符串
DateprototypetoArray 日期分割为数组
DateprototypeDatePart 取日期的部分信息
DateprototypeMaxDayOfDate 取日期所在月的最大天数
DateprototypeWeekNumOfYear 判断日期所在年的第几周
StringToDate 字符串转日期型
IsValidDate 验证日期有效性
CheckDateTime 完整日期时间检查
daysBetween 日期天数差
todayDate = new Date();
date = todayDategetDate();
month= todayDategetMonth() +1;
year= todayDategetYear();
documentwrite("今天是")
documentwrite("<br>")
if(navigatorappName == "Netscape")
{
documentwrite(1900+year);
documentwrite("年");
documentwrite(month);
documentwrite("月");
documentwrite(date);
documentwrite("日");
documentwrite("<br>")
}
if(navigatorappVersionindexOf("MSIE") != -1)
{
documentwrite(year);
documentwrite("年");
documentwrite(month);
documentwrite("月");
documentwrite(date);
documentwrite("日");
}
if (todayDategetDay() == 5) documentwrite("星期五")
if (todayDategetDay() == 6) documentwrite("星期六")
if (todayDategetDay() == 0) documentwrite("星期日")
if (todayDategetDay() == 1) documentwrite("星期一")
if (todayDategetDay() == 2) documentwrite("星期二")
if (todayDategetDay() == 3) documentwrite("星期三")
if (todayDategetDay() == 4) documentwrite("星期四")
JavaScript获取当前日期时间同时显示星期几,具体代码如下:
<html>
<head>
<meta
>
以上就是关于js如何获取到当前年份 和当前的年份-1全部的内容,包括:js如何获取到当前年份 和当前的年份-1、JS如何获取当前系统时间、js如何去当前时间前一天的时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)