您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在查询期间将时间转换为本地时区中的日期

如何在查询期间将时间转换为本地时区中的日期

终于让它工作了!不是很漂亮(我希望有一个更干净的解决方案),但是这样做有效:

>> Payment.all(:conditions => 
              ["Date((payments.created_at at time zone 'UTC') 
                at time zone :timezone) >= :start_date and 
                Date((payments.created_at at time zone 'UTC') 
                at time zone :timezone) <= :end_date",
               :start_date => start_date, :end_date => end_date, 
               :timezone => 'Asia/Katmandu'])

不过,我并不真正喜欢这样做:

Date((payments.created_at at time zone 'UTC') at time zone 'Asia/Katmandu')

为何postgresql不允许您这样做?

Date(payments.created_at at 'Asia/Katmandu')
其他 2022/1/1 18:38:06 有570人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶