In Mainland China, when running the following command on a computer at 7 am, the resulting date is always for the previous day

ui.vision.9.16

{
“Command”: “executeScript_Sandbox”,
“Target”: “return new Date().toISOString().slice(0,10)”,
“Value”: “currDay”
}
or
{
“Command”: “executeScript”,
“Target”: “return new Date().toISOString().slice(0,10)”,
“Value”: “currDay”
}

The issue you’re encountering is due to the time zone difference between your local time and UTC (Coordinated Universal Time). The toISOString() method returns a date in UTC time zone, which is 8 hours behind the time zone in Mainland China (CST, UTC+8).

When you run the command at 7 am in Mainland China, it is still 11 pm of the previous day in UTC. Therefore, the date returned by toISOString() will be the previous day.

To solve this issue, you can adjust the date to your local time zone before slicing it.

Here’s an updated script that uses the local timezone of whatever machine it runs on:

{
  "Name": "get_local_date",
  "CreationDate": "2024-6-6",
  "Commands": [
    {
      "Command": "executeScript_Sandbox",
      "Target": "var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); month = month < 10 ? '0' + month : month; day = day < 10 ? '0' + day : day; return year + '-' + month + '-' + day;",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Current LOCAL Date=${a}",
      "Value": "green",
      "Description": ""
    }
  ]
}