Wondering if I should remove the time data normally stored. We're using postgres
and node.js
where a DateTime would get returned from our API as:
2013-07-01T00:00:00.000Z
Yet since this field should only represent a date, I feel reformatting before return like this would make it more clear that time is not relevant:
2013-07-01
Thoughts?
There is no date format in JSON, there's only strings a de-/serializer decides to map to date values. However, JavaScript built-in JSON object and ISO8601 contains all the information to be understand by human and computer and does not relies on the beginning of the computer era (1970-1-1).
JSON does not directly support the date format and it stores it as String. However, as you have learned by now that mongo shell is a JavaScript interpreter and so in order to represent dates in JavaScript, JSON uses a specific string format ISODate to encode dates as string.
stringify converts DateTimeOffset to UTC format #1710.
environment. set('currentdate', moment(). format(("YYYY-MM-DD"))); {{$timestamp}} -> predefined variable gets the current timestamp, Since you need date the above one should work.
If you are representing a calendar date, there is no time or timezone. The short representation makes more sense.
Unfortunately, new Date(string) in many javascript implementations can do bad things to you.
new Date('2015-09-23')
Tue Sep 22 2015 20:00:00 GMT-0400 (Eastern Daylight Time)
The simplest way out of the problem is not to use javascript's Date - this type matches up with DateTimeOffset in other languages. It is a bad way to represent calendar date values.
But, you're probably going to use javascript's Date anyway. The next simplest "fix" is to avoid standard representations (since standard representations get interpretted as DateTimeOffset with UTC). Here are two possibilities:
Use "/" instead of "-".
new Date('2015/09/23')
Wed Sep 23 2015 00:00:00 GMT-0400 (Eastern Daylight Time)
Use a 3 digit month - the leading zeroes will be discarded.
new Date('2015-009-23')
Wed Sep 23 2015 00:00:00 GMT-0400 (Eastern Daylight Time)
If you have javascript on the both the client and server side, you're done. If you have something else on the server side, you should consider what the server language will do if it sees non-standard date formats coming in.
As an API user, I would much rather receive the long form of a date.
For a few reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With