how to force Date.parse() in javascript to convert to local time and date instead of UTC

I have an application where I am calling the function Date.parse as follows:

Date.parse('2021-02-22' + ' ' + '13:00')

However, when I run the app locally and in production (AWS), this function seems to return two different results. Locally it returns 1613959200000 while in production it returns 1613998800000. Upon further investigation, 1613959200000 seems to convert to 2021-02-22 at 13:00 in Australian Eastern Daylight time, while 1613998800000 converts to 2021-02-22 at 13:00 in UTC time. Is there a way I can force Date.parse() to convert for the local timezone of the client/browser, rather than UTC? (in this case Australian Eastern Daylight time, but I’d want it to work for all timezones).

EDIT: I have tried using date objects, in order to produce a date/time object that is in sync with the local timezone, but it doesn’t seem to work as shown in the code below:

var d = new Date("Mon Feb 22 2021 00:00:00 GMT+1100 (Australian Eastern Daylight Time)");

var ds = d.toString();

var e = new Date(2021,2,22,0,0)
var es = e.toString();

console.log(ds === es) //returns false for some reason

207 thoughts on “how to force Date.parse() in javascript to convert to local time and date instead of UTC”

  1. My coder is trying to convince me to move to .net from PHP.

    I have always disliked the idea because of the costs.

    But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am anxious about
    switching to another platform. I have heard very
    good things about blogengine.net. Is there a way I can transfer all my
    wordpress content into it? Any help would be greatly appreciated!

    Reply
  2. Howdy! This post could not be written any better! Reading through this post reminds me of my previous room
    mate! He always kept talking about this. I will forward this post to him.

    Pretty sure he will have a good read. Thank you for sharing!

    Reply
  3. This is really interesting, You are a very skilled blogger.
    I have joined your rss feed and look forward
    to seeking more of your wonderful post. Also, I’ve shared your website in my social
    networks!

    Reply
  4. Thanks for your marvelous posting! I certainly enjoyed reading
    it, you are a great author. I will ensure that I bookmark your blog and will
    come back sometime soon. I want to encourage that you continue your great writing, have a nice afternoon!

    Reply
  5. Just wish to say your article is as astonishing.
    The clearness in your post is just cool and i could assume you are
    an expert on this subject. Well with your permission let me to grab your feed
    to keep up to date with forthcoming post. Thanks a million and please keep up
    the enjoyable work. quest bars http://j.mp/3C2tkMR quest bars

    Reply
  6. Good post. I learn something new and challenging on sites
    I stumbleupon everyday. It will always be interesting to read through content from other writers and use a little
    something from other sites.

    Reply
  7. I’m extremely impressed with your writing abilities
    as well as with the format on your weblog. Is this a paid theme or did you modify it yourself?

    Anyway keep up the nice quality writing, it’s rare to look a great weblog like this
    one nowadays..

    Reply
  8. It’s actually a great and useful piece of info.
    I am satisfied that you just shared this useful info with us.
    Please stay us informed like this. Thank you for sharing.

    Reply
  9. I’ve been surfing on-line greater than 3 hours today, but I never found
    any interesting article like yours. It is beautiful price enough
    for me. In my view, if all website owners and bloggers made good
    content material as you probably did, the web might be a lot more useful than ever before.

    Reply
  10. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several e-mails with the same comment.
    Is there any way you can remove people from that service?
    Bless you!

    Reply
  11. I do trust all of the concepts you have offered to your post.
    They’re very convincing and will definitely work.
    Nonetheless, the posts are very quick for newbies.
    May just you please lengthen them a little from subsequent time?
    Thank you for the post.

    Reply
  12. Great blog here! Also your web site loads up very fast!
    What web host are you using? Can I get your affiliate link to
    your host? I wish my website loaded up as quickly
    as yours lol

    Check out my website :: coupon

    Reply
  13. My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using Movable-type on several websites
    for about a year and am concerned about switching to
    another platform. I have heard great things about blogengine.net.
    Is there a way I can import all my wordpress
    content into it? Any help would be greatly appreciated!

    Reply
  14. Hey There. I found your blog using msn. This is a really well written article.
    I will be sure to bookmark it and return to read more of your useful information. Thanks for
    the post. I will definitely return.

    Reply

Leave a Comment