Search code examples
google-apps-scriptgoogle-tasks

Why is Time not setting when inserting new task using Task Service?


I am trying to insert new task with due date and time in Google Tasks using Tasks Service. The issue i am facing is that date is setting correctly while time is not setting. The code is given below:

I had tried all the solutions given on stackoverflow and other platform, none of them worked.

      var task = Tasks.newTask().setTitle(data[i]);
      task.setDue("2019-6-25T10:10:10.000Z");
      Tasks.Tasks.insert(task, taskList.id);

I expect both the date and time to be set but only date is setting.


Solution

  • The official document says as follows.

    Due date of the task (as a RFC 3339 timestamp). Optional. The due date only records date information; the time portion of the timestamp is discarded when setting the due date. It isn't possible to read or write the time that a task is due via the API.

    Unfortunately, in the current stage, by above specification, even if 2019-6-25T10:10:10.000Z is used for due, it becomes 2019-06-25T00:00:00.000Z. So it seems that in order to modify the time, it is required to manually modify it.

    Reference: