问题描述
我正在为cgi应用程序使用SQLite,但是我所处的时区与运行该东西的共享服务器的时区不同。我可以在SQLite中以某种方式设置时区,这样我就不需要将时间转换弄乱我的应用程序,并且可以在SQL中使用NOW()之类的东西了吗?如果不是:我还有其他选择吗?
I'm using SQLite for my cgi application, but the timezone I'm in is different from that of the shared server this stuff is running on. Can I set my timezone somehow in SQLite so I don't need to mess up my application with time conversions and I can use things like NOW() in my SQL? If not: what are my other options?
推荐答案
SQLite无法设置连接时区,因为它是针对性的面向嵌入式数据库的用途-无论您使用什么方式更改C库,localtime()输出都应适用于SQLite。这在MacOS上对我有用:
SQLite doesn't have a way to set the connection time zone because it's targeted towards embedded database uses--whatever you use to change your C library localtime() output should work for SQLite. This works for me on MacOS:
$ TZ=America/New_York sqlite3 dbfile "select datetime('now','localtime');"
2010-01-06 09:53:28
$ TZ=America/Los_Angeles sqlite3 dbfile "select datetime('now','localtime');"
2010-01-06 06:53:41
这篇关于如何为SQL设置时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!