如何设置Google任务到期日 [英] How to set Google Tasks Due Date

查看:148
本文介绍了如何设置Google任务到期日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在apps脚本中设置谷歌任务服务的任务到期日?



任务服务



尝试将此值设置为给定日期,似乎只更新本地值,而不是服务器值,因为tehhowch表明

  task.due = new Date(); 

您如何更新服务器?下面是我试过的:

  var x = {
due:new Date()
};
Tasks.Tasks.update(x,MDE2NzI3NTAzNjc5NTQ1ODY5MTY6MDow,任务);

但会抛出错误

 无效值:格式无效:Tue Apr 10 20:45:26 GMT-04:00 2018






完成项目



我使用此代码创建此项目以保留Google Tasks截至日期:



保留Google任务更新

解决方案

根据Google Tasks API文档任务资源到期参数必须是 RFC 3339时间戳。因此,而不是Tue Apr 10 20:45:26 GMT-04:00 2018它应该是2018-04-11T0:45: 26.000Z。查看相关问题:生成类似RFC 3339的时间戳到Google Tasks API?



这与任务的其他 datetime 属性使用的格式相同,所以如果有人要记录任务:

  console.log(Tasks.Tasks.get(listId,taskId)); 

然后到期完成更新属性(如果存在)将指示所需的格式。

从Google Apps脚本中的本地JavaScript 日期,这最简单的方法如下:

  function getExtension(listId,taskId){
var now = new Date();
var deadline = new Date(Date.UTC(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate()+ 7));
var newTask = {
due:Utilities.formatDate(deadline,GMT,yyyy-MM-dd'T'HH:mm:ss'Z')
};
//由于我们仅提供部分资源,因此请调用.patch()而不是.update()
Tasks.Tasks.patch(newTask,listId,taskId);
}


How do you set the due date for a task with the google tasks service in apps script?

Tasks Service

Trying to set this value to a given date, but this seems to only update the local value not the server value as tehhowch suggests

task.due = new Date();

How do you update the server? Here is what I tried

var x = {
    due: new Date()
};
Tasks.Tasks.update(x, "MDE2NzI3NTAzNjc5NTQ1ODY5MTY6MDow", task);

but it throws the error

Invalid value for: Invalid format: "Tue Apr 10 20:45:26 GMT-04:00 2018"


Completed Project

I used this code to create this project for keeping Google Tasks up to date:

Keep Google Tasks Updated

解决方案

In accordance with the Google Tasks API documentation for the Task resource, the due parameter must be an RFC 3339 timestamp. So instead of "Tue Apr 10 20:45:26 GMT-04:00 2018" it should be "2018-04-11T0:45:26.000Z". See related question: Generate an RFC 3339 timestamp similar to Google Tasks API?

This is the same format used by other datetime properties of the task, so if one were to log the task:

console.log(Tasks.Tasks.get(listId, taskId));

Then the due, completed and updated properties, if present, would indicate the required format.

From a native Javascript Date in Google Apps Script, this is easiest done as:

function getExtension(listId, taskId) {
  var now = new Date();
  var deadline = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 7));
  var newTask = {
    due: Utilities.formatDate(deadline, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'")
  };
  // Since we supply only a partial resource, call .patch() rather than .update()
  Tasks.Tasks.patch(newTask, listId, taskId);
}

这篇关于如何设置Google任务到期日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆