久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <i id='EHfTU'><tr id='EHfTU'><dt id='EHfTU'><q id='EHfTU'><span id='EHfTU'><b id='EHfTU'><form id='EHfTU'><ins id='EHfTU'></ins><ul id='EHfTU'></ul><sub id='EHfTU'></sub></form><legend id='EHfTU'></legend><bdo id='EHfTU'><pre id='EHfTU'><center id='EHfTU'></center></pre></bdo></b><th id='EHfTU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EHfTU'><tfoot id='EHfTU'></tfoot><dl id='EHfTU'><fieldset id='EHfTU'></fieldset></dl></div>

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

      <tfoot id='EHfTU'></tfoot>

          <bdo id='EHfTU'></bdo><ul id='EHfTU'></ul>
      1. <legend id='EHfTU'><style id='EHfTU'><dir id='EHfTU'><q id='EHfTU'></q></dir></style></legend>
      2. Javascript Date.toJSON 沒有得到時區偏移

        Javascript Date.toJSON don#39;t get the timezone offset(Javascript Date.toJSON 沒有得到時區偏移)

              <bdo id='uhJo7'></bdo><ul id='uhJo7'></ul>

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

              1. <legend id='uhJo7'><style id='uhJo7'><dir id='uhJo7'><q id='uhJo7'></q></dir></style></legend>
                  <tbody id='uhJo7'></tbody>

                <tfoot id='uhJo7'></tfoot>

                <i id='uhJo7'><tr id='uhJo7'><dt id='uhJo7'><q id='uhJo7'><span id='uhJo7'><b id='uhJo7'><form id='uhJo7'><ins id='uhJo7'></ins><ul id='uhJo7'></ul><sub id='uhJo7'></sub></form><legend id='uhJo7'></legend><bdo id='uhJo7'><pre id='uhJo7'><center id='uhJo7'></center></pre></bdo></b><th id='uhJo7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uhJo7'><tfoot id='uhJo7'></tfoot><dl id='uhJo7'><fieldset id='uhJo7'></fieldset></dl></div>
                1. 本文介紹了Javascript Date.toJSON 沒有得到時區偏移的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  問題是我使用的是這樣的代碼:

                  Well the problem is that I was using code like this:

                  new Date().toJSON().slice(0, 10)
                  

                  將我的日期作為 YYYY-MM-DD 字符串,然后我在一些 mysql 查詢和一些條件語句中使用它作為參數.在一天結束時,我沒有得到正確的日期,因為它仍然在前一天(我的時區偏移量是 +2/3 小時).

                  to get my date as YYYY-MM-DD string, then I use it like parameter in some mysql queries and in some condition statements. In the end of the day I wasn't getting the right date since it was still in the previous day (my timezone offset is +2/3 hours).

                  我沒有注意到 toJSON 方法沒有考慮到您的時區偏移,所以我最終得到了這個 hacky 解決方案:

                  I haven't noticed that the toJSON method does not take into account your timezone offset, so I've ended up with this hacky solution:

                  var today = new Date();
                  today.setHours( today.getHours()+(today.getTimezoneOffset()/-60) );
                  console.log(today.toJSON().slice(0, 10));
                  

                  有沒有更優雅的解決方案?

                  Is there a more elegant solution?

                  • 這里是測試代碼:http://jsfiddle.net/simo/qwhYw/
                  • JavaScript toJSON 方法
                  • JavaScript 日期對象

                  推薦答案

                  ECMAScript 中的日期對象在內部是 UTC.時區偏移量用于當地時間.

                  Date objects in ECMAScript are internally UTC. The timezone offset is used for local times.

                  Date.prototype.toJSON 的規范說它使用 Date.prototype.toISOString,表示時區始終為 UTC".您的解決方案正在做的是將日期對象的 UTC 時間值偏移時區偏移量.

                  The specification for Date.prototype.toJSON says that it uses Date.prototype.toISOString, which states that "the timezone is always UTC". What your solution is doing is offsetting the UTC time value of the date object by the timezone offset.

                  考慮將您自己的方法添加到 Date.prototype,例如

                  Consider adding your own method to Date.prototype, e.g.

                  Date.prototype.toJSONLocal = function() {
                    function addZ(n) {
                      return (n<10? '0' : '') + n;
                    }
                    return this.getFullYear() + '-' + 
                           addZ(this.getMonth() + 1) + '-' + 
                           addZ(this.getDate());
                  } 
                  

                  編輯

                  如果你想擠出額外的性能,以下應該更快:

                  Edit

                  If you want to squeeze extra performance, the following should be faster:

                  Date.prototype.toJSONLocal = (function() {
                      function addZ(n) {
                          return (n<10? '0' : '') + n;
                      }
                      return function() {
                        return this.getFullYear() + '-' +
                               addZ(this.getMonth() + 1) + '-' +
                               addZ(this.getDate());
                      };
                  }())
                  

                  但這有點過早優化的味道,所以除非你在很短的時間內調用它數千次,否則我不會打擾.

                  But that smacks of premature optimisation, so unless you are calling it thousands of times in a very short period, I wouldn't bother.

                  這篇關于Javascript Date.toJSON 沒有得到時區偏移的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)

                  <tfoot id='sxijd'></tfoot>

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

                        <tbody id='sxijd'></tbody>

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

                            <bdo id='sxijd'></bdo><ul id='sxijd'></ul>
                            <legend id='sxijd'><style id='sxijd'><dir id='sxijd'><q id='sxijd'></q></dir></style></legend>
                            主站蜘蛛池模板: 狠狠亚洲 | 日韩成人专区 | 成人18亚洲xxoo | 亚洲色图网址 | 成人久久18免费网站图片 | 亚洲三区在线观看 | 在线欧美a| 天天插天天狠天天透 | 久久久99国产精品免费 | 日本不卡一区二区三区在线观看 | 91久色 | 免费三级网站 | 精精国产xxxx视频在线播放7 | 久久久黑人 | 91精品国产自产在线老师啪 | 国产剧情一区 | 成人h视频在线 | 欧美日韩在线成人 | 伦理午夜电影免费观看 | 中文字幕一区二区三区四区 | 欧美成人第一页 | 91久久久www播放日本观看 | 久久精品国产一区二区三区不卡 | 欧美日韩精品区 | 91就要激情| 免费在线观看毛片 | 久久久精品一区 | 在线播放国产一区二区三区 | 久草电影网 | 神马影院一区二区三区 | 久久乐国产精品 | 久草网站| 日本高清视频网站 | 日韩av在线中文字幕 | 韩国精品在线 | 欧美日韩国产一区二区三区 | 国产成人精品一区二区在线 | 日韩精品1区2区3区 国产精品国产成人国产三级 | 国产亚洲一区二区精品 | 久久久一二三 | 日韩高清在线观看 |