[英]How to change current time on a web page?
I need to change current time on my web page.我需要更改网页上的当前时间。 How to change it?
如何改变它?
I am displaying current time using below code:我使用以下代码显示当前时间:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="description" content="Digital Clock created with JavaScript" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Current System Time</title> <!-- <link rel="stylesheet" href="css/style.css"> --> </head> <body> <div id="not-clock"><span>Current System Time:</span></div> <div id="clock"></div> <div id="day"></div> <div id="date"></div> <script src="scriptTime.js"></script> </body> </html>
Please set the current time on the web page as per this example.请按照此示例在网页上设置当前时间。
HTML HTML
<div class='time-frame'>
<div id='date-part'></div>
<div id='time-part'></div>
</div>
<br>
<input type='button' id='stop-interval' value='Stop time' />
**JS**
$(document).ready(function() {
var interval = setInterval(function() {
var momentNow = moment();
$('#date-part').html(momentNow.format('YYYY MMMM DD') + ' '
+ momentNow.format('dddd')
.substring(0,3).toUpperCase());
$('#time-part').html(momentNow.format('A hh:mm:ss'));
}, 100);
$('#stop-interval').on('click', function() {
clearInterval(interval);
});
});
**CSS**
.time-frame {
background-color: #000000;
color: #ffffff;
width: 300px;
font-family: Arial;
}
.time-frame > div {
width: 100%;
text-align: center;
}
#date-part {
font-size: 1.2em;
}
#time-part {
font-size: 2em;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.