如何在网页上显示moment.js时间?

时间:2022-12-01 16:03:35

I'm using moment.js and I put the following script on my webpage:

我正在使用moment.js并将以下脚本放在我的网页上:

<script>
    var newYork    = moment.tz("2014-06-01 12:00", "America/New_York");
    $('time').append(newYork);
</script>

and the html code:

和HTML代码:

<div id="time">
    some text
</div>

I would like to display the current time in new york, but all I see is some text. How can I put the time in that div? Thanks!

我想在纽约显示当前时间,但我看到的只是一些文字。我怎么能把时间放在那个div中?谢谢!

2 个解决方案

#1


$('time') should actually be $('#time')

$('time')实际上应该是$('#time')

#2


assuming var newYork is correct try:

假设var newYork是正确的尝试:

var newYork    = moment.tz("2014-06-01 12:00", "America/New_York");
$('#time').append(newYork);

if you want to replace inner html do this:

如果要替换内部html,请执行以下操作:

$('#time').html(newYork);

#1


$('time') should actually be $('#time')

$('time')实际上应该是$('#time')

#2


assuming var newYork is correct try:

假设var newYork是正确的尝试:

var newYork    = moment.tz("2014-06-01 12:00", "America/New_York");
$('#time').append(newYork);

if you want to replace inner html do this:

如果要替换内部html,请执行以下操作:

$('#time').html(newYork);