In my Google Sheet, cell A3, there is a duration value of 00:01:00
Then I access this value in Google Sheets as so...
var my_time = my_sheet.getRange("A3").getValue();
var hms = Utilities.formatDate(my_time ,"GMT", "HH:mm:ss");
When I compare the two variables, I can't get the same duration time in both variables. Instead I have...
my_time | Date (1473042018) | Sat Dec 30 1899 00:01:00 GMT+0100 (CET)
hms | String | "23:01:00"
EDIT: Here is the public_file for testing; Here the code (accessible through the file):
function myFunction() {
var my_sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var result_cell = my_sheet.getRange("A4");
result_cell.clear();
var my_time = my_sheet.getRange("A3").getValue();
var hms = Utilities.formatDate(my_time ,"GMT", "HH:mm:ss");
result_cell.setValue(hms);}
What I am trying to do is get the duration value in cell A3, in a variable in Google Apps Script.
I don't understand why A3.getValue() returns "Sat Dec 30 1899 00:51:39 GMT+0100 (CET)" when the typed time is "00:01:00". I expected "Sat Dec 30 1899 00:01:00 GMT+0100 (CET)"
Below is a screenshot of my spreadsheet and code:
"HH:mm:ss"
to something else. For date and time patterns that are available to use, see the documentation at the following link: Link - Format Date and time patterns - Alan Wells