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

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

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

        • <bdo id='veNRj'></bdo><ul id='veNRj'></ul>
        <legend id='veNRj'><style id='veNRj'><dir id='veNRj'><q id='veNRj'></q></dir></style></legend>
      1. 如何在 JavaScript 中獲取 UTC 時間戳?

        How do I get a UTC Timestamp in JavaScript?(如何在 JavaScript 中獲取 UTC 時間戳?)
      2. <small id='M5fi4'></small><noframes id='M5fi4'>

        <tfoot id='M5fi4'></tfoot>

          • <legend id='M5fi4'><style id='M5fi4'><dir id='M5fi4'><q id='M5fi4'></q></dir></style></legend>
            • <bdo id='M5fi4'></bdo><ul id='M5fi4'></ul>

                    <tbody id='M5fi4'></tbody>
                  <i id='M5fi4'><tr id='M5fi4'><dt id='M5fi4'><q id='M5fi4'><span id='M5fi4'><b id='M5fi4'><form id='M5fi4'><ins id='M5fi4'></ins><ul id='M5fi4'></ul><sub id='M5fi4'></sub></form><legend id='M5fi4'></legend><bdo id='M5fi4'><pre id='M5fi4'><center id='M5fi4'></center></pre></bdo></b><th id='M5fi4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='M5fi4'><tfoot id='M5fi4'></tfoot><dl id='M5fi4'><fieldset id='M5fi4'></fieldset></dl></div>
                1. 本文介紹了如何在 JavaScript 中獲取 UTC 時間戳?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在編寫 Web 應用程序時,將(服務器端)所有日期時間作為 UTC 時間戳存儲在數據庫中是有意義的.

                  While writing a web application, it makes sense to store (server side) all datetimes in the DB as UTC timestamps.

                  當我注意到在 JavaScript 中的時區操作方面,您本身無法做很多事情時,我感到很驚訝.

                  I was astonished when I noticed that you couldn't natively do much in terms of Timezone manipulation in JavaScript.

                  我稍微擴展了 Date 對象.這個功能有意義嗎?基本上,每次我向服務器發送任何東西時,它都會是一個用這個函數格式化的時間戳......

                  I extended the Date object a little. Does this function make sense? Basically, every time I send anything to the server, it's going to be a timestamp formatted with this function...

                  你能看出這里有什么大問題嗎?還是換個角度的解決方案?

                  Can you see any major problems here? Or maybe a solution from a different angle?

                  Date.prototype.getUTCTime = function(){ 
                    return new Date(
                      this.getUTCFullYear(),
                      this.getUTCMonth(),
                      this.getUTCDate(),
                      this.getUTCHours(),
                      this.getUTCMinutes(), 
                      this.getUTCSeconds()
                    ).getTime(); 
                  }
                  

                  這對我來說似乎有點令人費解.我也不太確定性能.

                  It just seems a little convoluted to me. And I am not so sure about performance either.

                  推薦答案

                  1. 以這種方式構造的日期使用本地時區,導致構造的日期不正確.設置某個日期對象的時區是從包含時區的日期字符串構造它.(我無法讓它在舊版 Android 瀏覽器中運行.)

                  1. Dates constructed that way use the local timezone, making the constructed date incorrect. To set the timezone of a certain date object is to construct it from a date string that includes the timezone. (I had problems getting that to work in an older Android browser.)

                  請注意,getTime() 返回毫秒,而不是普通秒.

                  Note that getTime() returns milliseconds, not plain seconds.

                  對于 UTC/Unix 時間戳,以下內容就足夠了:

                  For a UTC/Unix timestamp, the following should suffice:

                  Math.floor((new Date()).getTime() / 1000)
                  

                  它會將當前時區偏移量計入結果中.對于字符串表示,David Ellis' 答案有效.

                  It will factor the current timezone offset into the result. For a string representation, David Ellis' answer works.

                  澄清一下:

                  new Date(Y, M, D, h, m, s)
                  

                  該輸入被視為當地時間.如果傳入UTC時間,結果會有所不同.觀察(我現在在 GMT +02:00,現在是 07:50):

                  That input is treated as local time. If UTC time is passed in, the results will differ. Observe (I'm in GMT +02:00 right now, and it's 07:50):

                  > var d1 = new Date();
                  > d1.toUTCString();
                  "Sun, 18 Mar 2012 05:50:34 GMT" // two hours less than my local time
                  > Math.floor(d1.getTime()/ 1000)
                  1332049834 
                  
                  > var d2 = new Date( d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate(), d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds() );
                  > d2.toUTCString();
                  "Sun, 18 Mar 2012 03:50:34 GMT" // four hours less than my local time, and two hours less than the original time - because my GMT+2 input was interpreted as GMT+0!
                  > Math.floor(d2.getTime()/ 1000)
                  1332042634
                  

                  另請注意,getUTCDate() 不能替代 getUTCDay().這是因為 getUTCDate() 返回 一個月中的哪一天;而 getUTCDay() 返回 星期幾.

                  Also note that getUTCDate() cannot be substituted for getUTCDay(). This is because getUTCDate() returns the day of the month; whereas, getUTCDay() returns the day of the week.

                  這篇關于如何在 JavaScript 中獲取 UTC 時間戳?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='UNTeV'></tfoot>
                    • <bdo id='UNTeV'></bdo><ul id='UNTeV'></ul>

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

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

                              <tbody id='UNTeV'></tbody>
                            主站蜘蛛池模板: 在线免费av观看 | 午夜免费看 | 国产目拍亚洲精品99久久精品 | 伊人焦久影院 | 99久久精品免费看国产高清 | 精品三级在线观看 | 超碰日本 | 91精品国产91久久久久久三级 | 色综合国产 | 亚洲日本中文 | 欧美精品在线一区 | 国产日日操 | 在线亚洲免费 | 九九久久精品视频 | 青青草中文字幕 | 亚洲一区二区三 | 久久综合久久自在自线精品自 | 成人黄色av网站 | 国产成人啪免费观看软件 | 一区二区三区网站 | 国产日韩亚洲欧美 | 欧美aa在线| 久夜精品 | 中文字幕在线视频精品 | 亚洲一一在线 | 日本不卡在线视频 | 免费精品久久久久久中文字幕 | 玖玖爱365| 午夜天堂精品久久久久 | 国产精品久久在线 | 久久久婷婷 | 女生羞羞网站 | 午夜精品导航 | 视频一区二区在线观看 | 欧美日韩综合 | 久久久久久久久久久福利观看 | 欧美一区二区免费视频 | 99久久精品免费看国产免费软件 | 99reav| 日日综合 | 91精品国产综合久久久久 |