python里面为什么系统的时区是东八,但是存数据还是存的标准时?,python时区,通过Django的API


通过Django的API来存:

pythonfrom django.db import modelsclass Chirp(models.Model):    content = models.TextField()    pub_time = models.DateTimeField(auto_now=True)    def __str__(self):        return self.content[:20]+ '...'

template中:

html{% for chirp in chirp_page %}        <div class="chirp_item">            <span class="timestamp">                {{ chirp.pub_time.hour }}:{{ chirp.pub_time.minute }},                {{ chirp.pub_time.day }}-{{ chirp.pub_time.month }}-{{ chirp.pub_time.year }}                &nbsp;说:{{ chirp.pub_time }}            </span>            <p class="chirp">{{ chirp.content }}</p>        </div>    {% endfor %}

显示效果示例:

因为我在Django项目里面也设置了时区,所以后面那个时间能正确显示(是这个原因吧。。。),但是通过属性来取的时候就跟数据库里一样了,看下面的图。

数据库中(注意time_zone):

系统的时区:

编橙之家文章,

评论关闭