python里面为什么系统的时区是东八,但是存数据还是存的标准时?,python时区,通过Django的API
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 }} 说:{{ chirp.pub_time }} </span> <p class="chirp">{{ chirp.content }}</p> </div> {% endfor %}
显示效果示例:
因为我在Django项目里面也设置了时区,所以后面那个时间能正确显示(是这个原因吧。。。),但是通过属性来取的时候就跟数据库里一样了,看下面的图。
数据库中(注意time_zone):
系统的时区:
编橙之家文章,
相关内容
- django1.8 出现NoReverseMatch错误怎么解决?,,django1.8 出现
- django读取日志并写入db数据库中,怎么样用页面展示出
- python3 类型Type str doesn't support the buffer API?,python3buffe
- Tornado里面self.write("hello")出现"Broken pipe Error"怎么
- requests爬取代理网站ip验证,登陆ip网站查询ip不变的原
- 用python将序列化之后的 json 存储在 mysql 中并且对于开发
- 编程语言的选择: Why choose Ruby or Python over PHP for web dev
- Django Web开发里面的url的重定向问题,比如这个abc.com/
- CentOS系统Python的版本太low了,该怎么升级呢》,centos
- Scrapy pipeline数据模块出现问题的解决,scrapypipeline,Scr
评论关闭