简体   繁体   中英

How to display moment.js time on a webpage?

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

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

and the html code:

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

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

assuming var newYork is correct try:

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

if you want to replace inner html do this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM