• <bdo id='ZiTmw'></bdo><ul id='ZiTmw'></ul>
    1. <tfoot id='ZiTmw'></tfoot>

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

      <legend id='ZiTmw'><style id='ZiTmw'><dir id='ZiTmw'><q id='ZiTmw'></q></dir></style></legend>
      <i id='ZiTmw'><tr id='ZiTmw'><dt id='ZiTmw'><q id='ZiTmw'><span id='ZiTmw'><b id='ZiTmw'><form id='ZiTmw'><ins id='ZiTmw'></ins><ul id='ZiTmw'></ul><sub id='ZiTmw'></sub></form><legend id='ZiTmw'></legend><bdo id='ZiTmw'><pre id='ZiTmw'><center id='ZiTmw'></center></pre></bdo></b><th id='ZiTmw'></th></span></q></dt></tr></i><div id='ZiTmw'><tfoot id='ZiTmw'></tfoot><dl id='ZiTmw'><fieldset id='ZiTmw'></fieldset></dl></div>

      1. getFullYear 在一年的第一天返回前一年

        时间:2024-04-20
        <tfoot id='S6Z7q'></tfoot>

            • <bdo id='S6Z7q'></bdo><ul id='S6Z7q'></ul>
                <i id='S6Z7q'><tr id='S6Z7q'><dt id='S6Z7q'><q id='S6Z7q'><span id='S6Z7q'><b id='S6Z7q'><form id='S6Z7q'><ins id='S6Z7q'></ins><ul id='S6Z7q'></ul><sub id='S6Z7q'></sub></form><legend id='S6Z7q'></legend><bdo id='S6Z7q'><pre id='S6Z7q'><center id='S6Z7q'></center></pre></bdo></b><th id='S6Z7q'></th></span></q></dt></tr></i><div id='S6Z7q'><tfoot id='S6Z7q'></tfoot><dl id='S6Z7q'><fieldset id='S6Z7q'></fieldset></dl></div>
              1. <small id='S6Z7q'></small><noframes id='S6Z7q'>

              2. <legend id='S6Z7q'><style id='S6Z7q'><dir id='S6Z7q'><q id='S6Z7q'></q></dir></style></legend>

                    <tbody id='S6Z7q'></tbody>

                  本文介绍了getFullYear 在一年的第一天返回前一年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试仅从日期中提取年份,但由于某种原因,它在一年的第一天返回了前一年.

                  I'm trying to pull just the year out of a date, but for some reason on the first day of the year its returning the year previous.

                  new Date('2012-01-01').getFullYear()
                  

                  将返回2011"并且

                  new Date('2012-01-02').getFullYear()
                  

                  将返回2012"

                  关于我做错了什么有什么好的想法吗?或对此进行修复会有所帮助.

                  Any good ideas on what I'm doing wrong? or a fix for this would be helpful.

                  推荐答案

                  new Date('2012-01-01') 将解析日期,假设它是 UTC.创建的 Date 对象包含您的时区,因此在打印 getYear() 的结果时会考虑到这一点.如果你在 GMT-anything,那意味着你要回到前一年.您可以通过调用 Date.prototype.getUTCFullYear() 忽略时区并仅处理 UTC.

                  new Date('2012-01-01') will parse the date assuming it's in UTC. The created Date object incorporates your timezone, so it will take that into account when printing out the result of getYear(). If you're in GMT-anything, that means you're going back to the previous year. You can ignore timezones and deal with just UTC by calling Date.prototype.getUTCFullYear().

                  这篇关于getFullYear 在一年的第一天返回前一年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内? 下一篇:javascript中的序数

                  相关文章

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

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

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