简体   繁体   English

流星-MongoDb-如何获取当前数据时间和未来日期时间之间的剩余秒数

[英]Meteor - MongoDb - How to get seconds remaining between current data time and future date time

I want to get seconds remaining between a current dataTime and future dateTime. 我想获得当前dataTime和将来的dateTime之间剩余的秒数。

I am using Meteor + MongoDb. 我正在使用Meteor + MongoDb。

In Mongo DataTime is saved like this: 在Mongo中,DataTime的保存方式如下:

2015-12-11T06:14:39.671Z

I want seconds remaining between current datatime and future or expiry datetime. 我希望在当前数据时间与未来或到期日期时间之间还剩下几秒钟。

keep your time data in epoch format which is basically storing data in milliseconds. 将您的时间数据保持为epoch格式,基本上以毫秒为单位存储数据。 then you'll be easy able to compare using momentJS or substracting. 那么您可以轻松地使用momentJS或减法进行比较。 And in MongoDB , this data will be stored as Number type not Date MongoDB ,此数据将存储为Number类型而不是Date

var time= (new Date).getTime();

this piece of code will return time in milliseconds. 这段代码将返回以毫秒为单位的时间。

The javascript Date can handle the sample input as listed in your question. javascript日期可以处理您的问题中列出的示例输入。 If that format is consistant, the following should get you your answer: 如果该格式一致,则以下内容将为您提供答案:

var difference = (new Date(databaseDate).getTime()-Date.now())/1000;

Where Date.getTime() and Date.now() are in milliseconds (hence the 1000). 其中Date.getTime()和Date.now()以毫秒为单位(因此为1000)。

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

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