【问题标题】:How to change current time on a web page?如何更改网页上的当前时间?
【发布时间】:2020-02-10 06:04:32
【问题描述】:

我需要更改网页上的当前时间。怎么改?

我正在使用以下代码显示当前时间:

<!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>

【问题讨论】:

  • 既然你有 php 作为标签,试试这个:
  • 你问How to change it?-> 的意思是你想展示某种递减计时器?
  • 使用 setInterval,间隔为 1 秒或 1 分钟,具体取决于您的时钟是如何制作的?
  • 你为什么不显示scriptTime.js - 你的代码的基本部分?澄清您的实际问题,否则您的问题将因不清楚而被关闭。
  • @Quasimodo'sclone 这里是:

标签: javascript php html time


【解决方案1】:

请按照本例设置网页上的当前时间。

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    相关资源
    最近更新 更多