<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Date 對象常用操作 ## 時間格式 <span style="font-size: 20px;">GMT(格林尼治平時)</span> Greenwich Mean Time,GMT 是指位于英國倫敦郊區的皇家格林尼治天文臺的標準時間,因為本初子午線被定義在通過那里的經線。 由于地球每天的自轉是有些不規則的,而且正在緩慢減速,因此格林尼治時間已經不再被作為標準時間使用。現在的標準時間,是由原子鐘報時的協調世界時(UTC)。 所以我們也從 MDN 上的文檔看到對于`toGMTString()`的解釋是: > Returns a string representing the Date based on the GMT (UT) time zone. Use toUTCString() instead. <span style="font-size: 20px;">UTC(世界標準時間)</span> 協調世界時,又稱世界標準時間或世界協調時間,簡稱UTC(從英文「Coordinated Universal Time」/法文「Temps Universel Cordonné」而來),是最主要的世界時間標準,其以原子時秒長為基礎,在時刻上盡量接近于格林尼治平時 <span style="font-size: 20px;">CST(北京時間)</span> 北京時間,China Standard Time,中國標準時間。在時區劃分上,屬東八區,比協調世界時早 8 小時,記為 UTC+8。 不過這個 CST 這個縮寫比較糾結的是它可以同時代表四個不同的時間: * Central Standard Time (USA) UT-6:00 * Central Standard Time (Australia) UT+9:30 * China Standard Time UT+8:00 * Cuba Standard Time UT-4:00 因此使用 CST 可能上傳時間給后端可能會存在一些 [問題](https://www.cnblogs.com/sanshi/archive/2009/08/28/1555717.html) 所以前端傳時間給后端盡量使用 UTC。 ## 時間戳 時間戳是指格林威治時間 1970 年 01 月 01 日 00 時 00 分 00 秒(北京時間 1970 年 01 月 01 日 08 時 00 分 00 秒)起至現在的秒數。(定義上是秒,JS 方法獲取的是毫秒) ```js var d = new Date() console.log(d.getTime() + " milliseconds since 1970/01/01") // 1564904334582 milliseconds since 1970/01/01 // Date 對象的 valueOf() 方法返回毫秒級時間戳 console.log(d.valueOf()) // 1564904334582 ``` ## 時間戳轉日期 ``` Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小時 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 } if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)) for(let k in o) if(new RegExp("("+ k +")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))) return fmt } ``` 使用 ``` function getTime (timeStamp) { return new Date(timeStamp * 1000).Format('yyyy-MM-dd hh:mm') } ``` ## 將 Date 對象轉換為字符串 ```js console.log(new Date()) // Sun Aug 04 2019 15:55:40 GMT+0800 (中國標準時間) console.log(new Date().toTimeString()) // 15:55:40 GMT+0800 (中國標準時間) console.log(new Date().toDateString()) // Sun Aug 04 2019 console.log(new Date().toUTCString()) // Sun, 04 Aug 2019 07:55:40 GMT console.log(new Date().toLocaleString()) // 2019/8/4 下午3:55:40 console.log(new Date().toLocaleTimeString()) // 下午3:55:40 console.log(new Date().toLocaleDateString()) // 2019/8/4 /** * toTimeString() 方法可把 Date 對象的時間部分轉換為字符串,并返回結果。 * toDateString() 方法可把 Date 對象的日期部分轉換為字符串,并返回結果。 * toUTCString() 方法可根據世界時 (UTC) 把 Date 對象轉換為字符串,并返回結果。 * toLocaleString() 方法可根據本地時間把 Date 對象轉換為字符串,并返回結果。 * toLocaleTimeString() 方法可根據本地時間把 Date 對象的時間部分轉換為字符串,并返回結果。 * toLocaleDateString() 方法可根據本地時間把 Date 對象的日期部分轉換為字符串,并返回結果。 */ ``` # Math 方法 | 方法 | 描述 | | :----| :---- | |floor(x)| 對數進行下舍入| |ceil(x) |對數進行上舍入| |round(x) |把數四舍五入為最接近的整數| |random() |返回 [0~1) 之間的隨機數| |max(x,y)| 返回 x 和 y 中的最高值,可以傳入多個參數| |min(x,y)| 返回 x 和 y 中的最低值| |abs(x)| 返回數的絕對值| |pow(x,y) |返回 x 的 y 次冪| |sqrt(x) |返回數的平方根| |sin(x) |返回數的正弦| |cos(x) |返回數的余弦| |tan(x)| 返回角的正切| |acos(x)| 返回數的反余弦值| |asin(x) |返回數的反正弦值| |atan(x) |以介于 -PI/2 與 PI/2 弧度之間的數值來返回 x 的反正切值| |atan2(y,x) |返回從 x 軸到點 (x,y) 的角度(介于 -PI/2 與 PI/2 弧度之間)| |exp(x) |返回 e 的指數| |log(x)| 返回數的自然對數(底為e)| # 參考鏈接 [https://www.w3school.com.cn/jsref/jsref\_obj\_date.asp](https://www.w3school.com.cn/jsref/jsref_obj_date.asp) [https://www.jb51.net/article/84563.htm](https://www.jb51.net/article/84563.htm) [https://github.com/lishengzxc/bblog/issues/5](https://github.com/lishengzxc/bblog/issues/5) [https://www.cnblogs.com/sanshi/archive/2009/08/28/1555717.html](https://www.cnblogs.com/sanshi/archive/2009/08/28/1555717.html)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看