Repository navigation
How can I save a ISO 8601 UTC date in Datastore with a date and time index #599
Description
Activity
I think what you want is...
{ start: Date.parse('2013-05-14T13:01:00.234Z'); }
or if you use Moment.js:
{ start: moment('2013-05-14T13:01:00.234Z').toDate(); }
/cc @ryanseys As I think he had some docs that explained this, but I don't see them live on the gh-pages hosted site.
- addedtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.api: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on May 14, 2015 Hi @jgeewax, I don't think that will work as
Dategives me a back a Date object in my local timezone (GMT+0100), which is then stored in the Datastore in UTC format.I want to pass in a UTC date string to begin with using something like
moment.utc().toJSON()var localTZ = moment('2013-05-14T13:01:00.234Z').toDate(); console.log(localTZ); // Tue May 14 2013 14:01:00 GMT+0100 (IST) <- Date Object Local TZ console.log(localTZ.toJSON()); // 2013-05-14T13:01:00.234Z <- UTC var utc = moment.utc('2013-05-14T13:01:00.234Z'); <- UTC console.log(utc.toJSON()); // 2013-05-14T13:01:00.234Z <- UTCHm, I think this is a question of broader scope than gcloud-node...
Any objection to taking this over to Stack Overflow? I think it's probably going to get answered better there.. You effectively need to get a timezone-aware Javascript
Dateobject... I believe that once you have that, gcloud-node will handle it properly, right @ryanseys ?Yep.
This might be a bug. I'll look into it now.
Nope doesn't look like a bug in our code, we just get the number of milliseconds since the last Epoch using:
var d = new Date(Date.parse('2013-05-14T13:01:00.234Z')); // set start to this object. d.getTime() // num of milliseconds since epoch - no notion of timezone here
then multiply by
1000to get microseconds and set that value totimestamp_microseconds_value.Here's showing that the date is properly parsed as UTC (same as GMT):
> new Date(Date.parse('2013-05-14T13:01:00.234Z')) Tue May 14 2013 09:01:00 GMT-0400 (EDT) > new Date(Date.parse('2013-05-14T13:01:00.234Z')).toUTCString() 'Tue, 14 May 2013 13:01:00 GMT'
To answer your original question, try this:
{ name: 'Meeting' start: new Date(Date.parse('2013-05-14T13:01:00.234Z')) }
@byrneciaran any update on whether this helped you?
I think we this one is covered, but @byrneciaran, feel free to re-open if it didn't work. Thanks for getting us to double check how we handle dates!
23 remaining items
- added a commit that references this issue
on Jan 28, 2026 - added 2 commits that reference this issue
on Feb 2, 2026 - added a commit that references this issue
on Feb 3, 2026 - added 2 commits that reference this issue
on Feb 3, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 17, 2026 - added a commit that references this issue
on Mar 18, 2026
Let's say I have some JSON with an ISO 8610 UTC date as follows:
How do I save this in Datastore with a date and time index created for the
startproperty ?I know in the googleapis node module I can create an entity like:
But, in gcloud-node, it seems I can only do something like:
which gives me a Javascript Date object in local time not a ISO 8601 UTC Date.