如何为SQL设置时区? [英] How to set timezone for SQL?

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

问题描述

我正在为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设置时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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