如何将datetime与时区插入SQLite? [英] How to insert datetime with timezone to SQLite?

查看:155
本文介绍了如何将datetime与时区插入SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道要插入日期时间这个格式 yyyy-mm-dd hh:mm:ss 应该使用。

I know that to insert a datetime this format yyyy-mm-dd hh:mm:ss should be used.

但是,我的数据集有一个时间戳字段,看起来像 yyyy-mm-dd hh:mm:ss +/- 0X:00 ,其中 X 可以占用很多值,与我计算机的本地时区不同。

However my dataset has a timestamp field that looks like yyyy-mm-dd hh:mm:ss +/-0X:00, where X can take many values and is different from my computer's local timezone.

向SQLite插入具有这种时区信息的datetime字段的最佳方法是什么?

What is the best way to insert a datetime field with such timezone information to SQLite?

推荐答案

SQLite的内置日期和时间函数只能理解没有时区信息的时间戳记字符串。

SQLite's built-in date and time function understand only timestamp strings without time zone information.

如果要处理时区,您必须

If you want to handle time zones, you have to either


  • 将所有时间戳转换为一个特定的时区(UTC),以便您可以在其上使用SQLite函数,并可将其用于排序;或者

  • 将时区信息留在那里,但是不要在SQL中但在应用程序中进行所有计算和排序。

这篇关于如何将datetime与时区插入SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆