应该是:
var daynow=daygetdate();
documentf1txt1value= daynow;]
给你个我用的时间函数,自己修改。
<script language=javascript>
var tTick;
function date() {
var enabled = 0; today = new Date();
var day; var date;
if(todaygetDay()==0) day = "星期日"
else if(todaygetDay()==1) day = "星期一"
else if(todaygetDay()==2) day = "星期二"
else if(todaygetDay()==3) day = "星期三"
else if(todaygetDay()==4) day = "星期四"
else if(todaygetDay()==5) day = "星期五"
else if(todaygetDay()==6) day = "星期六";
if (todaygetYear()>=2000)
date1 = (todaygetYear()) + "年" + (todaygetMonth() + 1 ) + "月" + todaygetDate() + "日 ";
else
date1 = (1900 + todaygetYear()) + "年" + (todaygetMonth() + 1 ) + "月" + todaygetDate() + "日 ";
return date1+day;
}
function tick() {
var hours, minutes, seconds, ap;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = todaygetHours();
intMinutes = todaygetMinutes();
intSeconds = todaygetSeconds();
if (intHours == 0) {
hours = "12:";
ap = "AM";
} else if (intHours < 12) {
hours = intHours+":";
ap = "AM";
} else if (intHours == 12) {
hours = "12:";
ap = "PM";
} else {
intHours = intHours - 12
hours = intHours + ":";
ap = "PM";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = hours+minutes+seconds+ap;
timeString = "<font color='red'>"+"<center>"+date()+" "+timeString+"</center>"+"</font>";
ClockinnerHTML = timeString
tTick=windowsetTimeout("tick();", 1000)
}
documentwriteln("<div id=Clock> </div>")
windowonload = tick
windowonunload = new Function("clearTimeout(tTick)")
</script>
<script>
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;
var Clock = documentgetElementById('Clock');
today = new Date();
intHours = todaygetHours();
intMinutes = todaygetMinutes();
intSeconds = todaygetSeconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜 ";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午 ";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午 ";
} else {
intHours = intHours - 12
hours = intHours + ":";
xfile = "下午 ";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = xfile+hours+minutes+seconds;
ClockinnerHTML = timeString;
now = new Date(),hour = nowgetHours()
if(hour < 6){ClockinnerHTML =timeString+",明天不用上班了吗"}
else if (hour < 8){ClockinnerHTML =timeString+",全新的一天!"}
else if (hour < 10){ClockinnerHTML =timeString+",早安!"}
else if (hour < 12){ClockinnerHTML =timeString+",加油,快午饭了!"}
else if (hour < 14){ClockinnerHTML =timeString+",中午外面的太阳大吗"}
else if (hour < 16){ClockinnerHTML =timeString+",喝杯咖啡提提神!"}
else if (hour < 18){ClockinnerHTML =timeString+",加油,快下班了!"}
else if (hour < 19){ClockinnerHTML =timeString+",下班了,回家注意安全!"}
else if (hour < 22){ClockinnerHTML =timeString+",晚上好!"}
else if (hour < 24){ClockinnerHTML =timeString+",夜深了!祝你做个好梦!"}
windowsetTimeout("tick();", 100);
}
windowonload = tick;
</script>
<html>
<body>
您好,<font color="#FF0000">现在时间是</font><span id="Clock" align="center" style="font-size: 12; color:#FF0000"></span>
</body>
</html>
=========================
你会满意的!!
使用Date对象可以获取时间相关的信息。
获取当前时间:
var date = new Date();var year = dategetFullYear();
var month = dategetMonth() + 1;
var day = dategetDate();
var hour = dategetHours();
var minute = dategetMinutes();
var second = dategetSeconds();
alert(year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second);
获取一星期前的时间:
var now = new Date();var date = new Date(nowgetTime() - 7 24 3600 1000);
var year = dategetFullYear();
var month = dategetMonth() + 1;
var day = dategetDate();
var hour = dategetHours();
var minute = dategetMinutes();
var second = dategetSeconds();
alert(year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second);
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 日期天数差
以上就是关于JavaScript中如何获得系统当前时间全部的内容,包括:JavaScript中如何获得系统当前时间、用JavaScript语言设计:在页面上显示当前的时间,格式如图所示。、js获取当前时间和一星期前的时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)