生成类似于Google Tasks API的RFC 3339时间戳? [英] Generate an RFC 3339 timestamp similar to Google Tasks API?

查看:423
本文介绍了生成类似于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的每项任务都包含一个更新的属性,如下所示:

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

2011-08-30T13:22:53.108Z

现在我想生成一个类似的时间戳,以便每一个我在我的应用程序上更新任务时设置了一个新的更新的值。要生成我正在使用的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所以(新的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/Reference/Global_Objects/Date

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

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