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

    2. <small id='KCv40'></small><noframes id='KCv40'>

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

      <tfoot id='KCv40'></tfoot>

        Google Apps 脚本 formatDate 使用用户的时区而不是

        时间:2023-10-11

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

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

            1. <tfoot id='JTKvg'></tfoot>
                <tbody id='JTKvg'></tbody>

                  本文介绍了Google Apps 脚本 formatDate 使用用户的时区而不是 GMT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一行在单元格中设置当前日期和时间:

                  I have a line that sets the current date and time in a cell:

                  sheet.getRange(1,1).setValue(new Date());
                  

                  然后我有一行可以根据该单元格的值创建格式化日期:

                  Then I have a line that creates a formatted date based on that cell's value:

                  var addedDate = sheet.getRange(1,1).getValue();
                  var addedTime = Utilities.formatDate(addedDate, "GMT", "hh:mm a");
                  

                  生成的 addedTime 似乎在 GMT 时区,我需要它在用户的时区.它通常是美国东部时间 (-0500),但如果我只是从时间中减去 5 小时,那么这并没有考虑夏令时 (-0400).

                  The resulting addedTime seems to be in the GMT time zone and I need it to be in the user's time zone. It will usually be US Eastern Time (-0500), but if I simply subtract 5 hours from the time then that doesn't account for daylight saving time (-0400).

                  我在这里查看了 formatDate 的文档:https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

                  I checked the documentation for formatDate here: https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

                  此处链接到官方 Java SimpleDateFormat 类文档:http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

                  which links to the official Java SimpleDateFormat class documentation here: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

                  ...但我无法找到有效时区列表来替换 GMT.

                  ... but I can't find a list of valid time zones there to replace the GMT with.

                  推荐答案

                  可以这样直接获取电子表格时区:

                  You can directly get the spreadsheet Time Zone like this :

                    var addedDate = sheet.getRange(1,1).getValue();
                    var addedTime = Utilities.formatDate(addedDate, SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "hh:mm a");
                  

                  在此处查看文档

                  但如果您想自己选择,Google Apps 脚本会使用这些格式:

                  but Google Apps Script uses these formats if you want to choose it yourself :

                  http://joda-time.sourceforge.net/timezones.html

                  这篇关于Google Apps 脚本 formatDate 使用用户的时区而不是 GMT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 moment.js 检测当前用户时区的 ID 下一篇:在用户的时区显示日期/时间 - 在客户端

                  相关文章

                  最新文章

                  • <bdo id='58vqA'></bdo><ul id='58vqA'></ul>
                • <tfoot id='58vqA'></tfoot>

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

                  <small id='58vqA'></small><noframes id='58vqA'>

                  <legend id='58vqA'><style id='58vqA'><dir id='58vqA'><q id='58vqA'></q></dir></style></legend>