英文:
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 ofyyyy
- ming that it would be the calendar-based year.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论