0

I have a Node.js + MongoDB server on OpenShift. Which timezone I need to format a date to be able to compare it with a date was created on server with var date = new Date() operation?

collection.find({'recordType' : recordType, 
                 'modificationDate' : $gte : new Date(modificationDate)}}, 
                {fields : {'modificationDate':0}}).toArray(function(err, results)
Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
János
  • 32,867
  • 38
  • 193
  • 353
  • 1
    It's not a good idea to rely on *Server Time* http://stackoverflow.com/questions/13364036/create-javascript-date-utc – Ali Dehghani Sep 12 '16 at 11:16

1 Answers1

1

After connecting to your gear via ssh, run date in the console, you will get the timezone information of the server. In my case, it is EDT.

enter image description here

But this is not a good idea because if OpenShift changes gear hosting location, or even decide to change time zone, this may not work. You can also change gear hosting location in some paid subscriptions.

So, it would be better to store date-time in UTC in your database. You can also store client timezone information in the database so that later you can change the time accordingly. Alternatively, you can store time in UTC timestamp.

new Date().toISOString() can give you date-time in UTC format. new Date()gives UTC timestamp in milliseconds.

You can use node-time to manipulate date-time according to different timezone.

Community
  • 1
  • 1
Sourav Ghosh
  • 1,964
  • 4
  • 33
  • 43