• <small id='pRkZK'></small><noframes id='pRkZK'>

    <i id='pRkZK'><tr id='pRkZK'><dt id='pRkZK'><q id='pRkZK'><span id='pRkZK'><b id='pRkZK'><form id='pRkZK'><ins id='pRkZK'></ins><ul id='pRkZK'></ul><sub id='pRkZK'></sub></form><legend id='pRkZK'></legend><bdo id='pRkZK'><pre id='pRkZK'><center id='pRkZK'></center></pre></bdo></b><th id='pRkZK'></th></span></q></dt></tr></i><div id='pRkZK'><tfoot id='pRkZK'></tfoot><dl id='pRkZK'><fieldset id='pRkZK'></fieldset></dl></div>
      <bdo id='pRkZK'></bdo><ul id='pRkZK'></ul>
    <legend id='pRkZK'><style id='pRkZK'><dir id='pRkZK'><q id='pRkZK'></q></dir></style></legend>

      <tfoot id='pRkZK'></tfoot>

      1. 无论用户的时区如何,如何始终将日期设置为东

        时间:2023-10-11
          <i id='BN8lp'><tr id='BN8lp'><dt id='BN8lp'><q id='BN8lp'><span id='BN8lp'><b id='BN8lp'><form id='BN8lp'><ins id='BN8lp'></ins><ul id='BN8lp'></ul><sub id='BN8lp'></sub></form><legend id='BN8lp'></legend><bdo id='BN8lp'><pre id='BN8lp'><center id='BN8lp'></center></pre></bdo></b><th id='BN8lp'></th></span></q></dt></tr></i><div id='BN8lp'><tfoot id='BN8lp'></tfoot><dl id='BN8lp'><fieldset id='BN8lp'></fieldset></dl></div>

            <legend id='BN8lp'><style id='BN8lp'><dir id='BN8lp'><q id='BN8lp'></q></dir></style></legend>
              <tbody id='BN8lp'></tbody>

            <tfoot id='BN8lp'></tfoot>
              1. <small id='BN8lp'></small><noframes id='BN8lp'>

                • <bdo id='BN8lp'></bdo><ul id='BN8lp'></ul>

                  本文介绍了无论用户的时区如何,如何始终将日期设置为东部时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个服务器在 Unix 时间给我的日期:1458619200000

                  I have a date given to me by a server in unix time: 1458619200000

                  注意:您标记为重复"的其他问题并未显示如何从 UNIX TIME 到达那里.我正在寻找 javascript 中的特定示例.

                  但是,我发现根据我的时区,我会得到两种不同的结果:

                  However, I find that depending on my timezone I'll have two different results:

                  d = new Date(1458619200000)
                  Mon Mar 21 2016 21:00:00 GMT-0700 (Pacific Daylight Time)
                  

                  //现在我将计算机设置为东部时间,我得到了不同的结果.

                  // Now I set my computer to Eastern Time and I get a different result.

                  d = new Date(1458619200000)
                  Tue Mar 22 2016 00:00:00 GMT-0400 (Eastern Daylight Time)
                  

                  那么我如何显示日期:1458619200000 ... 无论我的计算机的时区如何,始终处于东部时间(3 月 22 日)?

                  So how can I show the date: 1458619200000 ... to always be in eastern time (Mar 22) regardless of my computer's time zone?

                  推荐答案

                  您可以使用 getTimezoneOffset() 函数.例如,

                  You can easily take care of the timezone offset by using the getTimezoneOffset() function in Javascript. For example,

                  var dt = new Date(1458619200000);
                  console.log(dt); // Gives Tue Mar 22 2016 09:30:00 GMT+0530 (IST)
                  
                  dt.setTime(dt.getTime()+dt.getTimezoneOffset()*60*1000);
                  console.log(dt); // Gives Tue Mar 22 2016 04:00:00 GMT+0530 (IST)
                  
                  var offset = -300; //Timezone offset for EST in minutes.
                  var estDate = new Date(dt.getTime() + offset*60*1000);
                  console.log(estDate); //Gives Mon Mar 21 2016 23:00:00 GMT+0530 (IST)
                  

                  虽然,后面表示的语言环境字符串不会改变.此答案的来源在这篇文章中.希望这会有所帮助!

                  Though, the locale string represented at the back will not change. The source of this answer is in this post. Hope this helps!

                  这篇关于无论用户的时区如何,如何始终将日期设置为东部时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 MongoDB 中存储日期而不考虑时区 下一篇:Javascript Date.toJSON 没有得到时区偏移

                  相关文章

                  最新文章

                  <small id='cUjpk'></small><noframes id='cUjpk'>

                    <bdo id='cUjpk'></bdo><ul id='cUjpk'></ul>
                  1. <legend id='cUjpk'><style id='cUjpk'><dir id='cUjpk'><q id='cUjpk'></q></dir></style></legend>

                    1. <tfoot id='cUjpk'></tfoot>
                      <i id='cUjpk'><tr id='cUjpk'><dt id='cUjpk'><q id='cUjpk'><span id='cUjpk'><b id='cUjpk'><form id='cUjpk'><ins id='cUjpk'></ins><ul id='cUjpk'></ul><sub id='cUjpk'></sub></form><legend id='cUjpk'></legend><bdo id='cUjpk'><pre id='cUjpk'><center id='cUjpk'></center></pre></bdo></b><th id='cUjpk'></th></span></q></dt></tr></i><div id='cUjpk'><tfoot id='cUjpk'></tfoot><dl id='cUjpk'><fieldset id='cUjpk'></fieldset></dl></div>