I want the time to be displayed correctly.

Asked 2 years ago, Updated 2 years ago, 78 views

The description of the time is obviously strange, but I don't know how to cure it.

function myFunction(){
  let year = new Date().getFullYear();
  const startDate = new Date("2020/4/1 12:00");
  console.log(startDate);  
  console.log (startDate.getUTCMonth());
  console.log (startDate.getUTCFullYear());
  console.log (exchangeTIME (startDate));
}
function exchangeTIME (startDate) {
  const startDATE=
    startDate.getUTCFullYear()+("0"+(startDate.getUTCMonth()+1)).slic(-2)+
    ("0" + startDate.getUTCDate()) .slice(-2) + 'T' + ("0" + startDate.getUTCHours(-2)+
    ("0" + startDate.getUTCMinutes()) .slice(-2)+("0" + startDate.getUTCSeconds(-2);

  return startDATE;
}

[20-06-05 15:52:09:485 JST] Wed Apr 01 2020 12:00:00 GMT+0900 (Japan Standard Time)
[20-06-05 15:52:09:487 JST] 3
[20-06-05 15:52:09:489 JST] 2020
[20-06-05 15:52:09:491JST] 20200401T030000

Then, the output of time is strange.If "T030000" is the original, it should be "T120000".How can I display the time?

running under a GAS environment.

javascript google-apps-script

2022-09-30 21:46

1 Answers

I am using getUTCXXX series methods, but
These methods are
Agreed World Time
for the output.

If you want to use local browser and processing time,
Let's use getXXX method

getUTCMonth
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth

getMonth
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth


2022-09-30 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.