<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之旅 廣告
                ## 問題 Problem 你需要計算出一個相對的日期范圍,比如說“上個月”或者“下個月”。 You need to calculate a relative date range like “last month” or “next month”. ## 方法 Solution 在當前月份上做加法或者減法,這沒什么問題,要知道JavaScript的Date構造器會處理好這些計算。 Add or subtract from the current month, secure in the knowledge that JavaScript’s Date constructor will fix up the math. ~~~ # these examples were written in GMT-6 # Note that these examples WILL work in January! now = new Date # => "Sun, 08 May 2011 05:50:52 GMT" lastMonthStart = new Date 1900+now.getYear(), now.getMonth()-1, 1 # => "Fri, 01 Apr 2011 06:00:00 GMT" lastMonthEnd = new Date 1900+now.getYear(), now.getMonth(), 0 # => "Sat, 30 Apr 2011 06:00:00 GMT" ~~~ ## 討論 Discussion JavaScript的Date對象樂于處理星期或者月份上的上溢或者下溢的情況,并會對日期進行相應的調整。例如,你可以獲取三月的第42天,你會得到四月的第11天。 JavaScript Date objects will cheerfully handle underflows and overflows in the month and day fields, and will adjust the date object accordingly. You can ask for the 42nd of March, for example, and will get the 11th of April. JavaScript的日期對象的年份存儲的是從1900年來的第幾年,月份從0到11,而日期是從1到31。在上面的方案中,last_month_start獲取的是當前年份這個月的第一天,但是月份是從-1到10,如果月份是-1,則實際上Date會返回上一年的十二月份。 JavaScript Date objects store the year as the number of years since 1900, the month as an integer from 0 to 11, and the date (day of month) as an integer from 1 to 31\. In the solution above, last_month_start is obtained by asking for the first day of a month in the current year, but the month is -1 to 10\. If month is -1 the Date object will actually return December of the previous year: ~~~ lastNewYearsEve = new Date 1900+now.getYear(), -1, 31 # => "Fri, 31 Dec 2010 07:00:00 GMT" ~~~ 對于上溢也是一樣的: The same is true for overflows: ~~~ thirtyNinthOfFourteember = new Date 1900+now.getYear(), 13, 39 # => "Sat, 10 Mar 2012 07:00:00 GMT" ~~~
                  <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>

                              哎呀哎呀视频在线观看