[英]mysql query for timezone conversion
is there a way to convert from unix timestamp to GMT in mysql while running the query itself?? 有没有一种方法可以在运行查询本身的同时从Unix时间戳转换为mysql中的GMT? My query is as follows:
我的查询如下:
SELECT
r.name
, r.network
, r.namestring
, i.name
, i.description
, r.rid
, i.id
, d.unixtime // this is the unix time i am asking to print
, d.ifInOctets
FROM range AS r
INNER JOIN intranet AS i
ON r.rid = i.rid
INNER JOIN 1279080000_1_60 AS d
ON i.id = d.id
AND unixtime BETWEEN 1279113600 AND 1279115400 // range of unix time
WHERE r.network = "ITPN"
AND i.status = "active"
GROUP BY i.id AND d.unixtime
I was working with it in jdbc and tried numerous ways suggested in this forum to do the conversion but it does not seem to help. 我在jdbc中使用它,并尝试了本论坛中建议的多种方法来进行转换,但这似乎无济于事。
Can I convert it directly and print out while running the query itself? 我可以直接将其转换并在运行查询本身时打印出来吗? I want to display the date in hour:minutes.
我想以小时:分钟显示日期。 eg: 9:20.
例如:9:20。
Please help or if there is any link I can follow that would be great too. 请帮助,或者如果我可以跟随任何链接,那也很好。 Thank you,
谢谢,
Using FROM_UNIXTIME converts a UNIX timestamp to a MySQL DATETIME: 使用FROM_UNIXTIME可以将UNIX时间戳转换为MySQL DATETIME:
FROM_UNIXTIME(r.unixtime)
Then you can use CONVERT_TZ to get the DATETIME in a different timezone: 然后,您可以使用CONVERT_TZ来获取其他时区中的DATETIME:
CONVERT_TZ(FROM_UNIXTIME(r.unixtime), ?, 'GMT')
Problem is, you need to know the original timezone is - you have to update the ?
问题是,您需要知道原始时区是-您必须更新
?
with the correct timezone... 具有正确的时区...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.