0

Is there any pros or cons? (in case of storing date inside database)

In Meteor _id field doesn't represent insert time.

Also. I know that MongoDB expireAfterSeconds TTL doesn't work with Date.now() Seems like new Date() is more universal and you can always make Date.now() from it.

Anything else? This question is more about use cases. So if you had problems with any, let us know

Dmitry
  • 168
  • 2
  • 9
  • 4
    Possible duplicate of [Best way to store date/time in mongodb](http://stackoverflow.com/questions/3778428/best-way-to-store-date-time-in-mongodb) – Curtis Dec 15 '15 at 20:00
  • `new Date()` returns an object that includes numerous methods. `Date.now()` simply returns an integer. – Michel Floyd Dec 15 '15 at 21:35
  • 1
    Better? Depends on your use case. Generally, `new Date()` will be more useful. – JeremyK Dec 15 '15 at 21:36
  • Possible duplicate of [Performance - Date.now() vs Date.getTime()](http://stackoverflow.com/questions/12517359/performance-date-now-vs-date-gettime) –  Dec 17 '15 at 00:37

2 Answers2

1

new Date() is a much more object-oriented way of passing information around. It is generally the preferred method.

prop-f
  • 26
  • 2
  • That actually isn't right at all. Both new Date() and Date.now() are both perfect in terms of OO, and are semantically the same. Date.now() should be preferred, because it is cleaner and faster. –  Dec 17 '15 at 00:36
  • 1
    http://jsperf.com/gettime-vs-now-0 @LucasSunsi You're right but it helps with the actual proof – Billybobbonnet Dec 17 '15 at 09:45
0

Actually, they are semantically equivalent, although Date.now() is much faster.