How to set timezone for SQL?

萝らか妹 提交于 2019-12-11 14:04:49

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/2013542/how-to-set-timezone-for-sql

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