GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — How can I save a ISO 8601 UTC date in Datastore with a date and time index · Issue #599 · googleapis/google-cloud-node

How can I save a ISO 8601 UTC date in Datastore with a date and time index #599

New issue
Copy link
New issue
Copy link
Closed
Closed
How can I save a ISO 8601 UTC date in Datastore with a date and time index#599
Copy link
Assignees
stephenplusplus
Labels
api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.
Milestone
Datastore Stable

Description

@byrneciaran
byrneciaran
opened on May 14, 2015
Issue body actions

Let's say I have some JSON with an ISO 8610 UTC date as follows:

{
    name: 'Meeting'
    start: '2013-05-14T13:01:00.234Z'
}

How do I save this in Datastore with a date and time index created for the start property ?

I know in the googleapis node module I can create an entity like:

var entity = {
    key: { path: [{ kind: 'Employee' }] },
    properties: {
        name: { stringValue: 'Meeting' },
        start: { dateTimeValue: '2013-05-14T13:01:00.234Z' },
    }
};

But, in gcloud-node, it seems I can only do something like:

{
    name: 'Meeting'
    start: new Date()
}

which gives me a Javascript Date object in local time not a ISO 8601 UTC Date.

Activity

Next
  1. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    Contributor
    More actions

    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.

  2. jgeewax
    added
    type: questionRequest for information or clarification. Not an issue.
    docs
    api: datastoreIssues related to the Datastore API.
    on May 14, 2015
  3. jgeewax
    added this to the Datastore Stable milestone on May 14, 2015
  4. byrneciaran commented on May 14, 2015

    @byrneciaran
    byrneciaran
    on May 14, 2015
    Author
    More actions

    Hi @jgeewax, I don't think that will work as Date gives 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 <- UTC
    
  5. jgeewax commented on May 14, 2015

    @jgeewax
    jgeewax
    on May 14, 2015
    Contributor
    More actions

    Hm, 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 Date object... I believe that once you have that, gcloud-node will handle it properly, right @ryanseys ?

  6. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    Yep.

  7. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    This might be a bug. I'll look into it now.

  8. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    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 1000 to get microseconds and set that value to timestamp_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'
  9. ryanseys commented on May 14, 2015

    @ryanseys
    ryanseys
    on May 14, 2015
    Contributor
    More actions

    To answer your original question, try this:

    {
        name: 'Meeting'
        start: new Date(Date.parse('2013-05-14T13:01:00.234Z'))
    }
  10. ryanseys commented on May 24, 2015

    @ryanseys
    ryanseys
    on May 24, 2015
    Contributor
    More actions

    @byrneciaran any update on whether this helped you?

  11. stephenplusplus commented on Jun 4, 2015

    @stephenplusplus
    stephenplusplus
    on Jun 4, 2015
    Contributor
    More actions

    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!

  12. stephenplusplus
    closed this as completedon Jun 4, 2015
  13. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  14. 23 remaining items

  15. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    chore: release 5.1.0 (#599)

    cfcd56b
  16. GautamSharda
    added 2 commits that reference this issue on Feb 2, 2026

    feat: propagate spanIds (#599)

    7fcfd40

    chore: release 4.1.0 (#608)

    3fecd1c
  17. sofisl
    added a commit that references this issue on Feb 3, 2026

    feat(params): adds optional param types (#599)

    1b8d09b
  18. GautamSharda
    added 2 commits that reference this issue on Feb 3, 2026

    feat: propagate spanIds (#599)

    88af461

    chore: release 4.1.0 (#608)

    faa5a2f
  19. sofisl
    added 3 commits that reference this issue on Feb 4, 2026

    migrate code from googleapis/cloud-profiler-nodejs (#7087)

    288deb4

    chore(main): release 3.2.1 (#599)

    9324c53

    chore: release 5.1.0 (#599)

    aadf143
  20. sofisl
    added a commit that references this issue on Feb 17, 2026

    chore: release 5.1.0 (#599)

    a66ce6e
  21. sofisl
    added 2 commits that reference this issue on Feb 25, 2026

    chore: remove console.log in system test (#599)

    3ad75b3

    fix(deps): update dependency google-auth-library to v4 (#599)

    d98041e
  22. GautamSharda
    added a commit that references this issue on Mar 12, 2026

    chore(deps): update dependency @types/mocha to v8 (#599)

    ac0b040
  23. sofisl
    added a commit that references this issue on Mar 17, 2026

    chore(main): release 6.3.0 (#599)

    fc7268b
  24. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    chore: remove console.log in system test (googleapis#599)

    f2da5e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    • Datastore Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.