获取对象包括Django中的DateTimeField

时间:2015-07-22 08:52:48

标签: python django python-2.7

当我有一个模型时,它在字段中有DateTimeField。

我从模型中获取一个对象并获取DateTimeField的属性。

它有UTC的tzinfo。

示例:

  

datetime.datetime(2015,7,21,14,18,27,tzinfo = <UTC>

有什么可以显示除UTC之外的其他时区?

1 个答案:

答案 0 :(得分:0)

python “GMT”, “UTC”, “-500”, “-5:00”, “EDT”, “US/Eastern”, “America/New York”模块可用于将时区从一个转换为另一个。

这里有关于tzinfo的文档 - https://docs.python.org/2/library/datetime.html#tzinfo-objects

它非常聪明,可以创建时区名称甚至是国家/地区名称

a = datetime.datetime(2015, 7, 21, 14, 18, 27, tzinfo=<UTC>) a.replace(tzinfo="EST") - 来自策展

您可以使用以下方式创建新的日期时间:

$ make
clang++ -DNDEBUG -g2 -O3 -Wall -fPIC -march=native -pipe -c gcm.cpp
...
gcm.cpp:676:3: error: invalid operand for instruction
                AS2(    movd    WORD_REG(di), xmm...
                ^
./cpu.h:221:20: note: expanded from macro 'AS2'
        #define AS2(x, y) GNU_AS2(x, y)
                          ^
./cpu.h:216:27: note: expanded from macro 'GNU_AS2'
        #define GNU_AS2(x, y) "\n\t" #x ", " #y ";"
                             ^
<inline asm>:110:12: note: instantiated into assembly here
        movd rdi, xmm0;
                  ^~~~~
gcm.cpp:685:3: error: invalid operand for instruction
                AS2(    movd    WORD_REG(di), xmm...
                ^
./cpu.h:221:20: note: expanded from macro 'AS2'
        #define AS2(x, y) GNU_AS2(x, y)
                          ^
./cpu.h:216:27: note: expanded from macro 'GNU_AS2'
        #define GNU_AS2(x, y) "\n\t" #x ", " #y ";"
                                 ^
<inline asm>:117:12: note: instantiated into assembly here
        movd rdi, xmm1;
                  ^~~~~

您无法更改tzinfo,因为datetime对象是不可变的

相关问题