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

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

      <tfoot id='JsIkg'></tfoot>

      <legend id='JsIkg'><style id='JsIkg'><dir id='JsIkg'><q id='JsIkg'></q></dir></style></legend>

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

        如何在 JavaScript 中使用 ISO 8601 格式化帶有時區偏

        How to ISO 8601 format a Date with Timezone Offset in JavaScript?(如何在 JavaScript 中使用 ISO 8601 格式化帶有時區偏移的日期?)

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

            • <bdo id='9alYx'></bdo><ul id='9alYx'></ul>
            • <small id='9alYx'></small><noframes id='9alYx'>

            • <tfoot id='9alYx'></tfoot><legend id='9alYx'><style id='9alYx'><dir id='9alYx'><q id='9alYx'></q></dir></style></legend>
                • 本文介紹了如何在 JavaScript 中使用 ISO 8601 格式化帶有時區偏移的日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  目標:找到本地時間UTC時間偏移,然后構造如下格式的URL.

                  Goal: Find the local time and UTC time offset then construct the URL in following format.

                  示例網址:/Actions/Sleep?duration=2002-10-10T12:00:00?05:00

                  格式基于W3C 推薦.文檔說:

                  例如,2002-10-10T12:00:00?05:00(2002 年 10 月 10 日中午,美國中部夏令時和東部標準時間)等于 2002-10-10T17:00:00Z,比 2002-10-10T12:00:00Z 晚五個小時.

                  For example, 2002-10-10T12:00:00?05:00 (noon on 10 October 2002, Central Daylight Savings Time as well as Eastern Standard Time in the U.S.) is equal to 2002-10-10T17:00:00Z, five hours later than 2002-10-10T12:00:00Z.

                  所以根據我的理解,我需要通過 new Date() 找到我的當地時間,然后使用 getTimezoneOffset() 函數計算差異,然后將其附加到字符串結束.

                  So based on my understanding, I need to find my local time by new Date() then use getTimezoneOffset() function to compute the difference then attach it to the end of string.

                  1. 使用格式

                  var local = new Date().format("yyyy-MM-ddThh:mm:ss"); // 2013-07-02T09:00:00
                  

                • 按小時獲取 UTC 時間偏移量

                • Get UTC time offset by hour

                  var offset = local.getTimezoneOffset() / 60; // 7
                  

                • 構造 URL(僅限時間部分)

                • Construct URL (time part only)

                  var duration = local + "-" + offset + ":00"; // 2013-07-02T09:00:00-7:00
                  

                • 以上輸出表示我的當地時間是 2013/07/02 上午 9 點,與 UTC 的差異是 7 小時(UTC 比當地時間早 7 小時)

                  The above output means my local time is 2013/07/02 9am and difference from UTC is 7 hours (UTC is 7 hours ahead of local time)

                  到目前為止,它似乎有效,但如果 getTimezoneOffset() 返回負值,如 -120?

                  So far it seems to work but what if getTimezoneOffset() returns negative value like -120?

                  我想知道在這種情況下格式應該是什么樣子,因為我無法從 W3C 文檔中弄清楚.

                  I'm wondering how the format should look like in such case because I cannot figure out from W3C documentation.

                  推薦答案

                  這是一個簡單的幫助函數,它將為您格式化 JS 日期.

                  Here's a simple helper function that will format JS dates for you.

                  function toIsoString(date) {
                    var tzo = -date.getTimezoneOffset(),
                        dif = tzo >= 0 ? '+' : '-',
                        pad = function(num) {
                            var norm = Math.floor(Math.abs(num));
                            return (norm < 10 ? '0' : '') + norm;
                        };
                  
                    return date.getFullYear() +
                        '-' + pad(date.getMonth() + 1) +
                        '-' + pad(date.getDate()) +
                        'T' + pad(date.getHours()) +
                        ':' + pad(date.getMinutes()) +
                        ':' + pad(date.getSeconds()) +
                        dif + pad(tzo / 60) +
                        ':' + pad(tzo % 60);
                  }
                  
                  var dt = new Date();
                  console.log(toIsoString(dt));

                  這篇關于如何在 JavaScript 中使用 ISO 8601 格式化帶有時區偏移的日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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() 的限制?)

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

                          <tbody id='z0fiw'></tbody>
                          • <bdo id='z0fiw'></bdo><ul id='z0fiw'></ul>
                          • <small id='z0fiw'></small><noframes id='z0fiw'>

                            <legend id='z0fiw'><style id='z0fiw'><dir id='z0fiw'><q id='z0fiw'></q></dir></style></legend>
                            主站蜘蛛池模板: 91香蕉视频在线观看 | 成人在线h| 女同videos另类 | 亚洲日韩中文字幕一区 | 亚洲黄色av| 欧美精品一区二区在线观看 | 日本黄色免费片 | 国产精品美女一区二区三区 | 久久亚洲精品国产精品紫薇 | 成人综合视频在线 | 欧美激情一区二区三级高清视频 | 一区二区三区在线播放 | 日本在线视频一区二区 | 97国产爽爽爽久久久 | 日本成人二区 | 欧美在线一区二区三区 | 免费精品 | 97伦理影院| 久久久九九九九 | 国内精品一区二区三区 | 成人免费在线观看 | 在线免费观看毛片 | 亚洲中国字幕 | 久久伊人久久 | 久久一区二区视频 | 国产精品久久国产精品99 | 成人在线播放 | 亚洲黄色片免费观看 | 国产高清在线精品一区二区三区 | 欧美午夜影院 | 日韩欧美一区二区三区免费看 | 天天干b| 久久高清精品 | 日本特黄a级高清免费大片 特黄色一级毛片 | 久久综合一区二区三区 | 国产农村一级国产农村 | 日本成人中文字幕 | 日本黄色大片免费看 | 成人性视频在线播放 | 亚洲精品在线看 | 久久国产精品精品国产色婷婷 |