Meteor / JS Dates

So, I'm trying to create a schedule app in a meteor by creating projects and adding time entries. What for? that’s all I could come up with as a test application.

But I'm more used to working with PHP, in PHP I would just save a date field with a length of time. Right now, I am wondering what is the best wat to deal with dates in Meteor.

Do ... Am I doing the same thing where I store the date syntax string or is it a date time object? How would you deal with dates? (I'm only 3 hours in Meteor)

+4
source share
3 answers

The meteor also includes a momentjs library that handles dates and times very easily. You get a function for formatting and analysis.

The best way to save your time is with a Date object. This is because in Mongo you get a timestamp and deviation from GMT. Securing TimeZone.

To manipulate and display time, use momentjs.

+10
source

This hackpad community with recommended methods and packages for storing and using dates is very useful:

https://meteor.hackpad.com/Meteor-Cookbook-Using-Dates-and-Times-qSQCGFc06gH

The best way to represent dates in your collection documents is to use the Date object type directly. Date objects can be stored directly in collection documents. If we create a document, we can generate a Date object as one of the properties provided to the insert() collection method.

+2
source

I would suggest that you keep time in the era. This will make sorting and searching easier. Normally, getTime () takes time from an era in milliseconds, but you can divide by 1000 to get time in seconds. 1

 var d = new Date(); var seconds = d.getTime() / 1000; 

To convert to a local date, if you need it, you can simply

 var d = new Date(0); // The 0 there is the key, which sets the date to the epoch d.setUTCSeconds(seconds); 
+1
source

Source: https://habr.com/ru/post/1486748/


All Articles