谷歌电子表格的月份被减少了1。

huangapple go评论75阅读模式
英文:

Google Spreadsheet month is being decremented by 1

问题

我在我的安卓应用中通过应用脚本从谷歌电子表格中接收日期数据,我以yyyy-dd-MM'T'HH:mm:ss.SSS'Z'这种格式接收数据,我不知道为什么,因为在电子表格中,日期是以dd-MM-YYYY这种格式显示的,但主要问题是,当从电子表格接收日期时,月份MM会减少一,而且如果是01,它会变成31,这在我的应用程序中解析格式时会创建一个错误。请告诉我如何阻止对月份值进行减少。

英文:

I am receiving date in my android application from google spreadsheet through appscript and i am receiving this data in yyyy-dd-MM'T'HH:mm:ss.SSS'Z' this format and I dont know why because in spreadsheet date is in dd-MM-YYYY this format but the main issue is when receiving date from spreadsheet month MM is decremented by one and also if it is 01 it becomes 31 which creates an error in my application while parsing the format.
Please tell me how to stop this decrementing of month value.

答案1

得分: 1

我不知道你如何使用Apps Script检索和发送数据,但是

Apps Script提供了方法Utilities.formatDate

该方法允许在进一步处理数据之前对其进行格式化。

示例:

var sheet = SpreadsheetApp.getActive().getActiveSheet();
var date = sheet.getRange('A1').getValue();
var formattedDate = Utilities.formatDate(date, "GMT+2", "dd-MM-yyyy");
  • 指定时区很重要,否则日期可能会被错误地检索/传递。
  • 此外:如果使用YYYY代替yyyy - 意味着它将是基于日历的年份
英文:

I don't know how you retrieve and send the data with Apps Script, but

Apps Script features the method Utilities.formatDate

that allows to format the data before processing it further.

Sample:

var sheet = SpreadsheetApp.getActive().getActiveSheet();
var date = sheet.getRange('A1').getValue();
var formattedDate = Utilities.formatDate(date, "GMT+2", "dd-MM-yyyy");
  • It is important to specify the time zone, because otherwise the date might be retrieved / passed incorrectly.
  • Also: if you use YYYY instead of yyyy - ming that it would be the calendar-based year.

huangapple
  • 本文由 发表于 2020年4月8日 16:30:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/61096467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定