java可识别的规范时区_使用Tastypie显示可识别时区的日期

news/2024/7/9 23:56:40 标签: java, python, 大数据, vue, jvm

java可识别的规范时区

So you have made the decision to use timezone-aware dates and now you are building your cool REST API using Tastypie. Of course timezones are important to your application, so you want to expose them when Tastypie exposes dates in the API.

因此,您已经决定使用可识别 时区的日期 ,现在您正在使用Deliciouspie构建出色的 REST API。 当然,时区对您的应用程序很重要,因此您希望在Tastypie在API中公开日期时公开时区。

You have a very simple resource that exposes a Django model that has an attribute, for example:

您有一个非常简单的资源来公开具有属性的Django模型,例如:

Out of the box, you notice that the dates displayed by Tastypie are converted to naive format, no matter if your USE_TZ variable is set to True in Django settings!

开箱即用,您注意到无论在Django设置中USE_TZ变量是否设置为True ,Tastypie所显示的日期都将转换为幼稚格式!

Searching the Internet you find that there is a Tastypie setting called TASTYPIE_DATETIME_FORMATTING. This might fix it…

在Internet上搜索,您发现有一个称为TASTYPIE_DATETIME_FORMATTING的Deliciouspie设置。 这可能会解决...

Before, our timestamps were formatted like

之前,我们的时间戳格式如下

  • 2013-02-28T16:42:55.08
  • 2013-02-28T16:42:55.08

If we set TASTYPIE_DATETIME_FORMATTING to 'rfc-2822' (it defaults to ISO–8601), our timestamps are now displayed like this

如果我们将TASTYPIE_DATETIME_FORMATTING设置为'rfc-2822' (默认为ISO – 8601 ),则我们的时间戳现在将显示为

  • Thu, 28 Feb 2013 16:42:55 +0000
  • Thu, 28 Feb 2013 16:42:55 +0000

This is correct, but I think kind of ugly for an API (though good perhaps for email messages). I want my datetimes to be formatted using ISO-8601, but include the UTC offset. The solution? Write your own Tastypie serializer and override the behavior when serializing dates.

这是正确的,但是我认为API有点难看(尽管对于电子邮件消息可能很好)。 我希望我的日期时间使用ISO-8601进行格式化,但要包含UTC偏移量 。 解决方案? 编写自己的Tastypie 序列化程序,并在序列化日期时覆盖行为。

Of course, you now make all the resources in your application inherit from MyModelResource. Finally our dates will be printed like this:

当然,现在您可以使应用程序中的所有资源都继承自MyModelResource 。 最后,我们的日期将像这样打印:

  • 2013-02-28T16:42:55.08+00:00
  • 2013-02-28T16:42:55.08+00:00

翻译自: https://www.pybloggers.com/2013/03/displaying-timezone-aware-dates-with-tastypie/

java可识别的规范时区


http://www.niftyadmin.cn/n/982959.html

相关文章

Buildout食谱提示:hexagonit.recipe.download

How to handle difficult old-style add-ons. 如何处理困难的旧式附件。 Sometimes an “old-style” add-on is distributed as foo.tar.gz and extracts to foo/, but the package is called bar. This can be a problem when using the plone.recipe.productdistros recipe…

k8s-存储篇

本章目录 存储分类emptydirhostpathpvc,pv,nfs 一 k8s存储分类 我一直相信画出图来再去了解比较直观,下面是我总结的k8s存储的分类,供参考 k8s的存储常用的就是上面几种模式,分为临时存储,半持久化存储&am…

17229 Lry,你除了2还是2

17229 Lry,你除了2还是2 时间限制:1000MS 内存限制:65535K提交次数:282 通过次数:46 收入:22 题型: 编程题 语言: G;GCC Description Lry非常想带他的女神去看海,可Lry是一个穷小子,并没有足够的钱可以支付这笔高额的旅行费用,…

django收集静态文件_收集器:我们所有人的静态文件管理

django收集静态文件A little while ago I wrote a blog post talking about Git hooks. As an example in that post I wrote a post-commit hook that would minify and upload my static files to S3. 不久前,我写了一篇博客文章谈论Git钩子 。 作为该帖子中的一个…

Python社区对Corey Schafer的采访

For this week’s community interview, I am joined by Corey Schafer, of YouTube fame. 在本周的社区访谈中,我与YouTube名声大噪的Corey Schafer一同加入了会议。 Corey is a full-time content creator publishing regular Python tutorials on YouTube. In …

Docker与VM虚拟机的区别以及Docker的特点

一、本质上的区别: VM(VMware)在宿主机器、宿主机器操作系统的基础上创建虚拟层、虚拟化的操作系统、虚拟化的仓库,然后再安装应用; Container(Docker容器),在宿主机器、宿主机器操作系统上创建Docker引擎,在引擎的基础…

python并发程序_并发加速您的Python程序

python并发程序If you’ve heard lots of talk about asyncio being added to Python but are curious how it compares to other concurrency methods or are wondering what concurrency is and how it might speed up your program, you’ve come to the right place. 如果您…

【DockerVM】docker容器与虚拟机有什么区别?

各种虚拟机技术开启了云计算时代;而Docker,作为下一代虚拟化技术,正在改变我们开发、测试、部署应用的方式。那虚拟机与Docker究竟有何不同呢? 首先,大家需要明确一点,Docker容器不是虚拟机! …