I am from UTC +8 timezone, and when I try to convert 2014-06-04 12:51:53 +0800/ from Rails / timestamp to my timezone. But it only works in chrome, and all other users cannot use the UTC time zone. And the result is always a few seconds ago. Here is how I use it:
window.updateTimestamps = (elements)->
moment.lang('mn')
moment().tz("Asia/Ulaanbaatar").format()
elements.each( ->
timestamp = moment(new Date($(@).data('datetime')))
$(@).html(timestamp.fromNow())
)
$(document).on('ready', ->
moment.tz.add
zones:
"Asia/Ulaanbaatar": [
"7:7:32 - LMT 1905_7 7:7:32"
"7 - ULAT 1978 7"
"8 Mongol ULA%sT"
]
rules:
Mongol: [
"1983 1984 3 1 7 0 0 1 S"
"1983 1983 9 1 7 0 0 0"
"1985 1998 2 0 8 0 0 1 S"
"1984 1998 8 0 8 0 0 0"
"2001 2001 3 6 8 2 0 1 S"
"2001 2006 8 6 8 2 0 0"
"2002 2006 2 6 8 2 0 1 S"
]
links: {}
Here is the HTML I'm trying to convert:
<abbr class="time-ago" data-datetime="2014-06-04 12:51:53 +0800"></abbr>
Here is the code:
timeAgos = $('abbr.time-ago')
window.updateTimestamps(timeAgos)
setInterval(window.updateTimestamps, 60000, timeAgos)
Thanks for the answer. I have no idea? Plz help me :)
source
share