使用Podio API创建新项目或更新现有项目时,将DateTime字段值设置为:2016-10-21 14:15:00(例如).哪个时区将用于存储此DateTime?
例如.请求:
app_id = <some app with title and date fields> content = {'title' => 'Date set to "14:15"','date' => {'start' => '2016-10-21 14:15:00','end' => '2016-10-21 15:00:00'}} item = Podio::Item.create(app_id,'fields' => content)
结果:
'start_date_utc' => 2016-10-21 'end' => 2016-10-21 15:00:00 'end_date' => 2016-10-21 'end_date_utc' => 2016-10-21 'start_time_utc' => 12:15:00 'start_time' => 14:15:00 'start_date' => 2016-10-21 'start' => 2016-10-21 14:15:00 'end_time' => 15:00:00 'end_time_utc' => 13:00:00 'end_utc' => 2016-10-21 13:00:00 'start_utc' => 2016-10-21 12:15:00
这很好,因为我在14:15时看到了相同的时间值14:15但是如何控制和设置这个DateTime字段的特定时区?
解决方法
看起来Podio API非常聪明,并且知道我的时区.
以下是一些带有请求和结果的示例.
将DateTime字段设置为14:15:00,将其作为不同的用户和app进行身份验证.
content = {'date' => {'start' => '2016-10-21 14:15:00'}} Podio.client.authenticate_with_credentials(<user A>,<pass>) item_created_by_userA = Podio::Item.create(app_id,'fields' => content) Podio.client.authenticate_with_credentials(<user B>,<pass>) item_created_by_userB = Podio::Item.create(app_id,'fields' => content) Podio.client.authenticate_with_app(<app ID>,<app token>) item_created_by_app = Podio::Item.create(app_id,'fields' => content)
然后设置的值是:
item_created_by_userA: 'start' => 2016-10-21 14:15:00 'start_utc' => 2016-10-21 12:15:00 item_created_by_userB: 'start' => 2016-10-21 14:15:00 'start_utc' => 2016-10-21 21:15:00 item_created_by_app: 'start' => 2016-10-21 14:15:00 'start_utc' => 2016-10-21 14:15:00
然后值2016-10-21 14:15:00被API视为2016-10-21 14:15:00 0200因为userA时区设置为UTC 02,并且相同的值被API视为2016-10-21 14:15:00 -0700因为userB时区是UTC-07(在Podio中,在帐户设置中).如果作为app进行身份验证,则假设时区为UTC
所以,如果我想设置值2016-10-21 14:15:00 0800(让我假装我想设置吉隆坡的时区),那么我将首先将其转换为我自己的时区(无论在Podio中设置什么)帐户设置),然后发送到Podio API,如下所示:
date_as_str = "2016-10-22 14:15:00 +08:00" # trying to set value with UTC+08 date_with_tz = DateTime.parse(date_as_str).in_time_zone("Europe/copenhagen") # when copenhagen is userA's timezone date_to_send = date_with_tz.strftime('%Y-%m-%d %H:%M:%s') content = {'date' => {'start' => date_to_send}} Podio.client.authenticate_with_credentials(<user A>,'fields' => content)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。