简体   繁体   English

FromNow()中的moment.js错误

[英]moment.js error in FromNow()

I Use moment.js v.2.4.0 and i use this script for calculate how many time has passed 我使用moment.js v.2.4.0并使用此脚本计算已经过了多少时间

$(".time").append(moment.unix({{ mydb|date('U') }}).fromNow());

mydb return data like mydb返回数据之类的

$(".time").append(moment.unix(1387358178).fromNow());

(in my db sql = 2013-12-17 18:30:48)

and return the right data if my date on my computer is right 如果我的计算机上的日期正确,则返回正确的数据

if I change my date the difference is wrong. 如果我改变日期,差异是错误的。 Can i make a difference between two date without use time of client computer ? 我可以在没有客户端计算机使用时间的情况下改变两个日期吗?

No. Moment is just like the rest of your JavaScript. 不,时刻就像你的其他JavaScript一样。 If you're running it in your browser, then it will use the timestamp of the computer running the browser when you refer to "now". 如果您在浏览器中运行它,那么当您引用“now”时,它将使用运行浏览器的计算机的时间戳。

If this is important to you, you could consider passing the server's current timestamp and then using the "Time from X" functionality, instead of "Time from now" . 如果这对您很重要,您可以考虑传递服务器的当前时间戳,然后使用“Time from X”功能,而不是“Time from now”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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