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 776311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:25:33+00:00 2026-05-14T19:25:33+00:00

In an JS app, I receive timestamp (eq. 1270544790922 ) from server (Ajax). Basing

  • 0

In an JS app, I receive timestamp (eq. 1270544790922) from server (Ajax).

Basing on that timestamp I create Date object using:

var _date = new Date();
_date.setTime(1270544790922);

Now, _date decoded timestamp in current user locale time zone. I don’t want that.

I would like _date to convert this timestamp to current time in city of Helsinki in Europe (disregarding current time zone of the user).

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 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-14T19:25:33+00:00Added an answer on May 14, 2026 at 7:25 pm

    A Date object’s underlying value is actually in UTC. To prove this, notice that if you type new Date(0) you’ll see something like: Wed Dec 31 1969 16:00:00 GMT-0800 (PST). 0 is treated as 0 in GMT, but .toString() method shows the local time.

    Big note, UTC stands for Universal time code. The current time right now in 2 different places is the same UTC, but the output can be formatted differently.

    What we need here is some formatting

    var _date = new Date(1270544790922); 
    // outputs > "Tue Apr 06 2010 02:06:30 GMT-0700 (PDT)", for me
    _date.toLocaleString('fi-FI', { timeZone: 'Europe/Helsinki' });
    // outputs > "6.4.2010 klo 12.06.30"
    _date.toLocaleString('en-US', { timeZone: 'Europe/Helsinki' });
    // outputs > "4/6/2010, 12:06:30 PM"
    

    This works but…. you can’t really use any of the other date methods for your purposes since they describe the user’s timezone. What you want is a date object that’s related to the Helsinki timezone. Your options at this point are to use some 3rd party library (I recommend this), or hack-up the date object so you can use most of it’s methods.

    Option 1 – a 3rd party like moment-timezone

    moment(1270544790922).tz('Europe/Helsinki').format('YYYY-MM-DD HH:mm:ss')
    // outputs > 2010-04-06 12:06:30
    moment(1270544790922).tz('Europe/Helsinki').hour()
    // outputs > 12
    

    This looks a lot more elegant than what we’re about to do next.

    Option 2 – Hack up the date object

    var currentHelsinkiHoursOffset = 2; // sometimes it is 3
    var date = new Date(1270544790922);
    var helsenkiOffset = currentHelsinkiHoursOffset*60*60000;
    var userOffset = _date.getTimezoneOffset()*60000; // [min*60000 = ms]
    var helsenkiTime = new Date(date.getTime()+ helsenkiOffset + userOffset);
    // Outputs > Tue Apr 06 2010 12:06:30 GMT-0700 (PDT)
    

    It still thinks it’s GMT-0700 (PDT), but if you don’t stare too hard you may be able to mistake that for a date object that’s useful for your purposes.

    I conveniently skipped a part. You need to be able to define currentHelsinkiOffset. If you can use date.getTimezoneOffset() on the server side, or just use some if statements to describe when the time zone changes will occur, that should solve your problem.

    Conclusion – I think especially for this purpose you should use a date library like moment-timezone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little logging app (written in wxPython) that receives data from a
Do we need to install an app to receive some push from a service
We want all of our AJAX calls in our web app to receive JSON-encoded
i have little problem with boost::asio library. My app receive and process data asynchronously,
My app uses a WebRequest at certain points to get pages from itself. This
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
My app has a DataGridView object and a List of type MousePos. MousePos is
My app needs to build a buffer from all the selected cells on a
I'm trying to build a app that uses the SmsMessage class but there are
My app has many controls on its surface, and more are added dynamically at

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.