javascript - Add, subtract and compare date and time on Meteor Mongo -
i running collection on meteor mongo has field called last_activity
, 1 called expire_date
.
in particular case need items collection last_activity
n hours ago.
in second case have save expire_date
n months creation time (right now).
how can add or subtract date or time on mongo/meteor (if use different methods glad if explained both briefly) , make comparisons them?
plus, 1 best idea choose when getting database? save processing time if directly on mongo?
it depends on how store date. have @ least 2 options.
date.now() 1437215759517
or
new date() date 2015-07-18t10:36:04.981z
in first case amount of ms special point of time in linux(unix) world :d , can add time existing one. example:
1 week 7 * 1 days 7 * 24 hours 7 * 24 * 60 minutes 7 * 24 * 60 * 60 seconds 7 * 24 * 60 * 60 * 1000 ms
so in code have (1 week now):
expire_date = date.now() + 7 * (24 * 60 * 60 * 1000)
and yes. display date in eye-pleasing format suggest moment.js
date.now() 1437216383841 moment(date.now()).format('ll') "july 18, 2015" moment(date.now() + 7 * (24 * 60 * 60 * 1000)).fromnow() "in 7 days"
Comments
Post a Comment