需要帮助显示设置的动态日期和时间 [英] Need help displaying a set dynamic date and time
问题描述
假设目前 12/17/14 6:25:?? PM
与 ??
是秒,但时间和日期必须是动态的,并由第二个自己更新。
我非常感谢能够完成这项工作的一些帮助,我希望这一次我已经足够具体,但如果我没有请让我知道我可以这样,这不会再被阻止。
呃,你的问题有点含糊。你只需要一个带日期的时钟显示在你的网页上?除非你提供了一些代码,否则我不能将它添加到你现有的项目中,但我用HTML编写了一个工作代码。从W3School的一些灵感( http://www.w3schools.com ),我最终得出了这个结论:
<!DOCTYPE html>
< html>
< head>
< script>
函数startTime(){
var today = new Date();
var day = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt')。innerHTML =Date:+ day +/+ month +/+ year ++Clock:+ h +:+ m +: + S;
var t = setTimeout(function(){startTime()},500);
}
函数checkTime(i){
if(i <10){i =0+ i}; //在数字前面加零10
返回i;
}
< / script>
< / head>
< body onload =startTime()>
< div id =txt>< / div>
< / body>
< / html>
这是你的意思吗?
编辑只是我做了日期的变量。
Basically I want my website to display my local time and date for everyone to see.
Let's say it is currently 6:25 PM on December 17, 2014
in my time zone and a visitor to the site's time and date is at the same time 2:25 PM on December 18, 2014
. What I am basically trying to do is have my website display in that instance 12/17/14 6:25:?? PM
with ??
being the seconds but the time and date must be dynamic and update on its own by the second.
I would very much appreciate some help in being able to get this done and I hope I have been specific enough this time but if I haven't please let me know how I can be so this doesn't get blocked again.
Uhm, your question is a bit vague. You just want a clock with date to be shown on your webpage? Unless you provide some code, I can't add it to your existing project, but I made a working code in HTML. With some inspiration from W3School (http://www.w3schools.com) I ended up with this:
<!DOCTYPE html>
<html>
<head>
<script>
function startTime() {
var today=new Date();
var day = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML = "Date: " + day + "/" + month + "/" + year + " " + "Clock: " + h+":"+m+":"+s;
var t = setTimeout(function(){startTime()},500);
}
function checkTime(i) {
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
Is this what you mean?
The edit is just that I made variables of the date too.
这篇关于需要帮助显示设置的动态日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!