How to insert datetime with timezone to SQLite?

天大地大妈咪最大 提交于 2019-12-19 16:35:36

问题


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

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.

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


回答1:


SQLite's built-in date and time functions understand the timezone specification in these strings, but with different timezones, any other operations on these strings (even searches and comparisons) will not work correctly.

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

  • convert all timestamps to one specific time zone (UTC), so that you can use them for sorting and searching; or
  • leave the time zone information in there, but do all searching, sorting and other computations not in SQL but in your application.


来源:https://stackoverflow.com/questions/13316845/how-to-insert-datetime-with-timezone-to-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!