生成类似于 Google Tasks API 的 RFC 3339 时间戳?

Generate an RFC 3339 timestamp similar to Google Tasks API?(生成类似于 Google Tasks API 的 RFC 3339 时间戳?)
本文介绍了生成类似于 Google Tasks API 的 RFC 3339 时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在构建一个与 Google Tasks 同步的应用.作为同步的一部分,我想比较本地任务和 API 任务,看看哪个最近发生了变化.

I am in the process of building an app that syncs with Google Tasks. As part part of the syncing, I want to compare the local task and the API task, and see which one has been changed more recently.

来自 Google API 的每个任务都包含一个 updated 属性,如下所示:

Each task from Google's API contains an updated property, which looks like this:

2011-08-30T13:22:53.108Z

现在我想生成一个类似的时间戳,这样每次我更新应用程序上的任务时,它都会设置一个新的 updated 值.要生成我正在使用的 RFC 3339 时间戳 - http:///cbas.pandion.im/2009/10/generating-rfc-3339-timestamps-in.html 生成如下内容:

Now I would like to generate a timestamp similar to that, so that every time I update a task on my app it sets a new updated value. To generate the RFC 3339 timestamp I am using - http://cbas.pandion.im/2009/10/generating-rfc-3339-timestamps-in.html which generates something like this:

2011-08-30T09:30:16.768-04:00

问题是,API 日期总是以大于"本地日期的形式返回,即使本地日期较新也是如此.我猜这与两者之间的不同格式有关.

The issue is, the API date is always coming back as "greater" than the local date, even when the local date is newer. I'm guessing it has something to do with the different formatting between the two.

这里有两个日期,顶部来自 Google Tasks API(大约 10 分钟前),底部是一分钟前在本地生成的.当比较哪个更大时,它告诉我最高的是.

Here are two dates, the top is from the Google Tasks API (from about 10 minutes ago), and the bottom one was generated locally a minute ago. When compared which is greater, it's telling me the top one is.

2011-08-30T13:22:53.108Z
2011-08-30T09:41:00.735-04:00

我的格式错了吗?我在这里做错了什么?非常感谢您对此的任何帮助.

Is my formatting wrong? What I am doing wrong here? Any help on this is really appreciated.

推荐答案

格式是 ISO,所以 new Date().toISOString() 会给你那个格式.正如我正在阅读的那样,可能需要填充:

The formatting is ISO so new Date().toISOString() will give you that form. Which as I'm reading might need to be shimmed:

/* use a function for the exact format desired... */
function ISODateString(d){
 function pad(n){return n<10 ? '0'+n : n}
 return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate())+'T'
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())+'Z'}

var d = new Date();
print(ISODateString(d)); // prints something like 2009-09-28T19:03:12Z

来源:https://developer.mozilla.org/en/JavaScript/参考/Global_Objects/日期

这篇关于生成类似于 Google Tasks API 的 RFC 3339 时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)