Server Date

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    9 posts
    Member since:
    Dec 2014

    Posted 17 Jan 2015 Link to this post

    Hi, quick question, is there any way to get the server date using the Javascript SDK?

    Thanks,
    Daniel
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 19 Jan 2015 Link to this post

    Hi Daniel,

    There is no such utility method integrated in the SDK. You can register a Cloud Function that returns new Date to observe the server time. For instance:
    Everlive.CloudFunction.onRequest(function(request, response, done) {
        var date = new Date();
        response.body = {Result: date};
        done();
    });

    A GET request returns a similar formatted result:
    {
        "Result": "YYYY-MM-DDTHH:MM:SS.000Z"
    }

    In addition, could you please specify your use case for such method?

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Daniel
    Daniel avatar
    9 posts
    Member since:
    Dec 2014

    Posted 20 Jan 2015 in reply to Anton Dobrev Link to this post

    Hi Anton,

    Thanks for that, it works well.

    The use for the method in my web project is to calculate the difference in months between a given start date which is user defined and the current date, this then allows me to trigger certain events for a bit of gamification.

    Thanks again,
    Daniel
  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 22 Jan 2015 Link to this post

    Hi,

    Thanks for specifying this.

    You might also register another cloud function that handles the calculation itself when called if you do not need to make this client-side.

    Please, let me know if you have further questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top