Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1097391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:25:34+00:00 2026-05-17T00:25:34+00:00

I have a webservice that returns for example a DateTime object: DepartureDate. I use

  • 0

I have a webservice that returns for example a DateTime object: DepartureDate.
I use ajax to fetch this and in my view I convert the JSON date string to a javascript date object with this function:

function convertToDate(jsonDate) {
    return eval("new " + jsonDate.substring(1, jsonDate.length - 1));
}

The problem is that new Date() takes the local time on the clients computer in consideration, so clients in different countries get different dates. I want to get the exact date that was returned from the webservice.
Is there any easy way to accomplish this?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:25:34+00:00Added an answer on May 17, 2026 at 12:25 am

    The problem is that new Date() takes the local time on the clients computer in consideration

    Nope. Creating a new Date using the timestamp constructor takes a UTC time stamp.

    For example on my machine in UTC+1:

    new Date(0)   // Thu Jan 01 1970 01:00:00 GMT+0100 (CET)
    

    OK, the default toString displays this date as 01:00:00 which looks wrong, but that’s actually the correct time. 01:00:00 in UTC+1 is 00:00:00 in UTC, which is the moment described by timestamp 0.

    If you want to display the dates you’ve creating from a timestamp in UTC, use date.toUTCString() or fetch and format the consistuent parts of the date using getUTCFullYear(), getUTCMonth() etc.

    Please, though, no eval.

    new Date(parseInt(jsonDate.slice(6, -1), 10))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET WebService that returns an object of List public class Students
I have a web service that returns this string via the jQuery $.ajax() call
I have a basic web service that returns the following object as JSON: public
I have webservice that can return data in multiple formats. For example json and
I have a little bash program that calls a webservice that returns JSON data.
I have a WebService that returns XML in a SOAP response: <?xml version=1.0 encoding=utf-8
I have a webservice that returns a list of Clinics near a certain lat/long.
I have an application in which I have a webservice call that returns data
I have a RPC encoded PHP webservice that returns a simple soap envelope with
I have a webservice method that reads a photo and returns its byte data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.