[英]Extract date,month,year and month name from the unix timestamp with postgresql
I use postgres for the rails app and I have a unix timestamp
in postgresql db. 我为rails应用程序使用postgres,并且在postgresql db中有一个
unix timestamp
。 I have a requirement to select and group by
the dd-mm-yyyy
and by month name
. 我需要根据
dd-mm-yyyy
和month name
进行选择和group by
。
Consider I have the following unix timestamp 考虑我有以下unix时间戳
1425148200
1425148200
and I would need to change this to datetime and I used to_timestamp
which returned 我需要将其更改为datetime,并使用
to_timestamp
返回
2015-02-28 18:30:00 UTC
2015-02-28 18:30:00 UTC
and I tried to convert the datetime
to local timezone
using 我试图使用将
datetime
时间转换为local timezone
::timestamp without time zone AT TIME ZONE 'IST'
::不带时区的时间戳记时区“ IST”
but that did not give time in required timezone and instead it returned 但这没有在所需的时区给定时间,而是返回了
2015-02-28 16:30:00 UTC
2015-02-28 16:30:00 UTC
and I tried to get the date part using ::date
which returned 我试图使用
::date
获取日期部分,该日期部分返回
Sat, 28 Feb 2015
2015年2月28日,星期六
So please help me get the dd-mm-yyyy
in specified timezone
and month name(March) from the unix timestamp. 因此,请帮助我从Unix时间戳获取指定
timezone
和月份名称(3月)中的dd-mm-yyyy
。
Thanks in Advance! 提前致谢!
select to_char(to_timestamp('1425148200')::timestamptz at time zone 'UTC-5:30','DD-MM-YYYY & of course Month') 选择to_char(to_timestamp('1425148200'):: timestamptz在时区'UTC-5:30','DD-MM-YYYY,当然还有月份')
01-03-2015 & of course March
2015年1月3日,当然还有三月
It is postgres mistake I guess according to http://www.postgresql.org/docs/7.2/static/timezones.html 根据http://www.postgresql.org/docs/7.2/static/timezones.html我猜这是postgres错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.