标签: timestamp-with-timezone

c/c ++ strptime()不解析%Z时区名称

我是C的新手.当我练习C来隐蔽时间来刺激来回构造tm时.我注意到了一些差异.请告诉我做错了什么.

#include <string.h>
#include <stdio.h>
#include <time.h>

/* 
test different format string to strptime
" %A, %b %d, %X %z %Y "
" %A, %b %d, %X %Z %Y "
*/
int main(int argc,char *argv[])
{

   char date[] = "6 Mar 2001 12:33:45";
   char fmt[80];
   struct tm tm;

   if (argc==1) return 0;
   strcpy(fmt,argv[1]);
   memset(&tm, 0, sizeof(struct tm));
   if (strptime(date,"%d %b %Y %H:%M:%S",&tm)==NULL) printf("error\n");
   char buf[128];
   strftime(buf, sizeof(buf), fmt, &tm);
   printf("%s\n", buf);
   printf("%d\n", tm.tm_isdst);
   if (strptime(buf,fmt,&tm)==NULL) printf("error\n");
   else {
   printf("year: %d; …
Run Code Online (Sandbox Code Playgroud)

c timezone strptime timestamp-with-timezone

5
推荐指数
1
解决办法
6838
查看次数

如何在预准备语句中传递带有''(timestamp)的字符串?

我正在尝试执行以下查询

INSERT INTO hotspot(timestamp) VALUES 
(timestamp with time zone '2012-10-25 14:00:00 +05:00' at time zone 'EET');
Run Code Online (Sandbox Code Playgroud)

我想将时间戳作为变量传递.

我的时间戳列是带时区的时间戳类型.

你知道如何做到这一点吗?

当我做...(Java,Postgresql)

    String stm= "INSERT INTO hotspot(timestamp) VALUES(timestamp with time zone ? at time zone 'EET')";
    pst = con.prepareStatement(stm);
    pst.setString(1, "2012-08-24 14:00:00 +05:00");
    pst.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

我在"$ 1"或附近收到语法错误

无论如何我能克服这个错误吗?先感谢您!!

更新:我尝试通过以下方式使用setTimestamp ...

Calendar c=Calendar.getInstance(TimeZone.getTimeZone("GMT+05:00"));
String stm= "INSERT INTO hotspot(timestamp) VALUES(?)";
pst = con.prepareStatement(stm);
pst.setTimestamp(1,Timestamp.valueOf("2012-01-05 14:00:00"), c );
pst.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

我想数据库中的正确值应该是(关于我的本地时区是EET(+02))

2012-01-05 11:00:00 +02

但使用pgadmin我检查值,我得到

2012-01-05 14:00:00 +02

有什么建议?

postgresql syntax-error insert-update timestamp-with-timezone

5
推荐指数
1
解决办法
7517
查看次数

oracle 如何在内部存储带时区的时间戳

基于 Oracle 文档,它在内部以数字形式存储时间戳和时区的不同部分。我读了这篇文章http://www.orafaq.com/wiki/Timestamp ,它解释了时间戳内部格式的算法。所以我做了一个简单的测试来验证它。

 SQL> create table tz_test(id number, tz timestamp with time zone);

 Table created.

 SQL> insert into tz_test values(1, timestamp '1999-10-29 21:00:00 -7:00');

 1 row created.

 SQL> insert into tz_test values(2, timestamp '1999-10-29 21:00:00 US/Pacific');

 1 row created.

 SQL> select id, dump(tz, 10) from tz_test where tz=timestamp '1999-10-29 21:00:00 -7:00';

    ID     DUMP(TZ,10)
 --------------------------------------------------------------------------------

     1     Typ=181 Len=13: 119,199,10,30,5,1,1,0,0,0,0,13,60

     2     Typ=181 Len=13: 119,199,10,30,5,1,1,0,0,0,0,137,156
Run Code Online (Sandbox Code Playgroud)

orafaq 中的文章谈到了 oracle 如何存储时区偏移量,我的第一行测试证明了这一点。但是没有关于如何存储时区文字的内容。所以我很想知道它。我也想知道 oracle 在内部如何评估时间戳 '1999-10-29 21:00:00 -7:00' 和时间戳 '1999-10-29 21:00:00 US/Pacific' 是相同的。

oracle timestamp-with-timezone

5
推荐指数
1
解决办法
1878
查看次数

pandas to_Datetime 转换与时区感知索引

我有一个带有时区感知索引的数据框

>>> dfn.index
Out[1]: 
DatetimeIndex(['2004-01-02 01:00:00+11:00', '2004-01-02 02:00:00+11:00',
               '2004-01-02 03:00:00+11:00', '2004-01-02 04:00:00+11:00',
               '2004-01-02 21:00:00+11:00', '2004-01-02 22:00:00+11:00'],
              dtype='datetime64[ns]', freq='H', tz='Australia/Sydney')
Run Code Online (Sandbox Code Playgroud)

我把它保存在csv中,然后按如下方式阅读:

>>> dfn.to_csv('temp.csv')
>>> df= pd.read_csv('temp.csv', index_col=0 ,header=None )
>>> df.head()
Out[1]: 
                                1
0                                
NaN                        0.0000
2004-01-02 01:00:00+11:00  0.7519
2004-01-02 02:00:00+11:00  0.7520
2004-01-02 03:00:00+11:00  0.7515
2004-01-02 04:00:00+11:00  0.7502
Run Code Online (Sandbox Code Playgroud)

索引作为字符串读取

>>> df.index[1]
Out[3]: '2004-01-02 01:00:00+11:00'
Run Code Online (Sandbox Code Playgroud)

在转换 to_datetime 时,它​​会更改时间,因为它将 +11 增加到小时

>>> df.index = pd.to_datetime(df.index)
>>> df.index[1]
Out[6]: Timestamp('2004-01-01 14:00:00')
Run Code Online (Sandbox Code Playgroud)

我现在可以从索引中减去 11 小时来修复它,但是有没有更好的方法来处理这个问题?

我尝试在此处的答案中使用解决方案,但这会大大减慢代码速度。

python datetime pandas timestamp-with-timezone

5
推荐指数
1
解决办法
5216
查看次数

PostgreSQL 如何知道我当前是否在时区“CET”中使用 DST?

我在我的中找到了以下行postgresql.conf

timezone = 'CET'
Run Code Online (Sandbox Code Playgroud)

我也通过查询设置得到了这个:

postgres=# show timezone;
 TimeZone
----------
 CET
Run Code Online (Sandbox Code Playgroud)

无论如何,我们目前仍然有 DST 活动,下面的示例显示服务器知道这一点(+02 是 CEST):

postgres=# select now();
              now
-------------------------------
 2019-10-09 02:03:33.48477+02
Run Code Online (Sandbox Code Playgroud)

但也有 PostgreSQL 已知的时区,缩写为 DST CET,并且没有 DST。特别是,所有具有此缩写的时区都有偏移+01:

postgres=# select * from pg_timezone_names() where abbrev = 'CET';
      name      | abbrev | utc_offset | is_dst
----------------+--------+------------+--------
 Africa/Algiers | CET    | 01:00:00   | f
 Africa/Tunis   | CET    | 01:00:00   | f

postgres=# select * from pg_timezone_abbrevs where abbrev = 'CET';
 abbrev | utc_offset | is_dst
--------+------------+--------
 CET    | …
Run Code Online (Sandbox Code Playgroud)

postgresql timezone timestamp-with-timezone postgresql-9.6

5
推荐指数
0
解决办法
1987
查看次数

AthenaQueryError:Athena 查询失败:“NOT_SUPPORTED:不支持的 Hive 类型

我最近遇到以下错误“AthenaQueryError:Athena 查询失败:“NOT_SUPPORTED:不支持的 Hive 类型”,为此我遵循了此堆栈溢出链接:转换为带有时区的时间戳在 Athena 上失败

错误

整个问题的奇怪部分是,当我使用内部 python 插件时生成的 sql 查询工作正常,因为我在 Athena 中手动运行它,但在 jupyter 笔记本中却不起作用

hive presto timestamp-with-timezone amazon-athena

5
推荐指数
1
解决办法
3198
查看次数

Django时区感知DateTimeField默认值时区感知错误

我正在尝试将 DateTimeField 添加到我的 django 模型中,并以最大时间戳作为默认值。我已经弄清楚,Django 中的最大时间戳是 9999/12/31 23:59:59,与我的 postgres 数据库中使用的最大时间戳不同。当使用此时间戳作为字段的默认值时,我收到错误OverflowError: date value out of range。因此我尝试使用 9999/01/01 00:00:00 进行相同的操作,如下所示:

start_time = models.DateTimeField(null=False, default=datetime.datetime(9999,01,01,00,00,00,tzinfo=utc))

现在,当我将南迁移应用到数据库时,出现以下异常:

RuntimeWarning: DateTimeField received a naive datetime (9999-01-01 00:00:00) while time zone support is active.

在查看数据库时,我发现我的本地时区已应用于默认值:9999-01-01 00:00:00+01这使我得出结论,django 以某种方式忽略了时区意识,但我不知道为什么会这样。

附加信息:

Django TIME_ZONE 设置为“欧洲/柏林”

USE_TZ 为 True

任何帮助表示赞赏。

django django-models timestamp-with-timezone

4
推荐指数
1
解决办法
6347
查看次数

带有本地时区值的 Oracle 时间戳透明转换

据我所知,TIMESTAMP WITH LOCAL TIME ZONE值被透明地转换为和来自用户的会话时区。但是我从数据库中读取的值与之前插入的值不同。是否有我可以调整的数据库或会话参数来解决这个问题?

这是我的测试用例:

select systimestamp(0) from dual;

-- SYSTIMESTAMP   15/03/2017 19:01:13 +03:00

select dbtimezone from dual;

-- DBTIMEZONE     -07:00

create table test_timestamps
(
    id number generated by default on null as identity,
    systimestamp_col timestamp(0) with local time zone default on null systimestamp,
    sysdate_col timestamp(0) with local time zone default on null sysdate,
    current_timestamp_col timestamp(0) with local time zone default on null current_timestamp(0),
    date_col timestamp(0) with local time zone
);

alter session set time_zone='0:00';

insert into …
Run Code Online (Sandbox Code Playgroud)

oracle session timezone timestamp-with-timezone

4
推荐指数
2
解决办法
8797
查看次数

在 sequelize 查询中比较时间戳和日期

我有一createdAt列将值存储为"2018-11-07 15:03:16.532+00". 我想写这样的查询select * from table_name where createdAt = input_date,其中我input_date的只有日期值2018-11-07。我如何使用 编写此查询Sequelize

javascript postgresql node.js sequelize.js timestamp-with-timezone

4
推荐指数
2
解决办法
6849
查看次数

如何在 Rust 中从 PostgreSQL 读取带有时区(timestamptz)值的时间戳?

timestamptz当使用 postgres 版本 0.17.0 和 Rust 1.40.0 时,正确的 Rust 数据类型是什么?

我阅读了文档,Timestamp但不知道这意味着什么或如何实现它。

0.17.0-alpha.1 的自述文件有一个表,其中表示timezone对应于 Rust 类型 time::Timespec或,chrono::DateTime<Utc>但两者都不适合我。

当我尝试使用 Cargo.toml 中规定的功能时:

[dependencies]
postgres = {version="0.17.0-alpha.1", features=["with-chrono", "with-time"]}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

[dependencies]
postgres = {version="0.17.0-alpha.1", features=["with-chrono", "with-time"]}
Run Code Online (Sandbox Code Playgroud)

这是一些功能代码和相应的依赖项。我希望能够读取并打印每行的时区(注释掉)

主程序.rs

use postgres::{Client, Error, NoTls};
extern crate chrono;
use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc};
extern crate time;
use time::Timespec;

pub fn main() -> Result<(), Error> {
    let mut client = Client::connect("host=localhost user=postgres", NoTls)?;

    client.simple_query(
        "
        CREATE TABLE mytable …
Run Code Online (Sandbox Code Playgroud)

postgresql rust timestamp-with-timezone rust-cargo

4
推荐指数
1
解决办法
5952
查看次数