日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Clickhouse 时区

發(fā)布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Clickhouse 时区 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Clickhouse 時區(qū)

?

默認設(shè)置

Clickhouse默認是讀取操作系統(tǒng)的時區(qū) 我們可以通過操作系統(tǒng)命令和clickhouse的命令查看驗證:

Clickhouse> select now();
?
SELECT now()
?
┌───────────────now()─┐
│ 2020-07-11 23:47:56 │
└─────────────────────┘
?
1 rows in set. Elapsed: 0.003 sec.?
?
Clickhouse> exit;
Bye.
[root@hadoop ~]# date
Sat Jul 11 23:48:01 CST 2020
?
?
?
此時操作系統(tǒng)的時區(qū)和時間是:
# timedatectl
? ? ? Local time: Sat 2020-07-11 23:49:06 CST
? Universal time: Sat 2020-07-11 15:49:06 UTC
? ? ? ? RTC time: Sat 2020-07-11 15:49:05
? ? ? ?Time zone: Asia/Shanghai (CST, +0800)
? ? ?NTP enabled: n/a
NTP synchronized: no
?RTC in local TZ: no
? ? ? DST active: n/a
?
操作系統(tǒng)的命令:
# timedatectl list-timezones
ist-timezones 列出系統(tǒng)上支持的時區(qū)
set-timezone 設(shè)定時區(qū)
set-time 設(shè)置時間
set-btp 設(shè)置同步ntp
?
示例:設(shè)置時區(qū)示例:
timedatec修改時區(qū)
timedatectl set-timezone "America/New_York"
?
# timedatectl set-timezone Asia/Shanghai
ntp設(shè)置:
yum -y install ntp?
systemctl enable ntpd?
systemctl start ntpd
?同步時間
ntpdate -u cn.pool.ntp.org
clickhouse提供了配置的參數(shù)選型:

1.修改設(shè)置
sudo vim /etc/clickhouse-server/config.xml
?
<timezone>Asia/Shanghai</timezone>
?由于clickhouse是俄羅斯人主導(dǎo)開發(fā)的,默認設(shè)置為Europe/Moscow
2.重啟服務(wù)器:
sudo service clickhouse-server restart
?
?
我們可以看到選型的說明如下:
?<!-- Server time zone could be set here.
? ? ? ? ?Time zone is used when converting between String and DateTime types,
? ? ? ? ? when printing DateTime in text formats and parsing DateTime from text,
? ? ? ? ? it is used in date and time related functions, if specific time zone was not passed as an argument.
? ? ? ? ?Time zone is specified as identifier from IANA time zone database, like UTC or Africa/Abidjan.
? ? ? ? ?If not specified, system time zone at server startup is used.
? ? ? ? ?Please note, that server could display time zone alias instead of specified name.
? ? ? ? ?Example: W-SU is an alias for Europe/Moscow and Zulu is an alias for UTC.
? ? -->
? ? <!-- <timezone>Europe/Moscow</timezone> -->
?
時區(qū)在日期時間相關(guān)的函數(shù),若指定時區(qū)作為參數(shù)。在Datetime和String類型之間進行轉(zhuǎn)換。
時區(qū)的指定是按照IANA標準的時區(qū)庫指定的,可以在Linux系統(tǒng)中通過命令查詢
若不指定則使用系統(tǒng)啟動的時區(qū)。
?clickhouse相關(guān)的時區(qū)函數(shù):

Clickhouse> select formatDateTime(now(),'%F %T') as dt,toString(toDateTime(dt),'Asia/Shanghai') as BJ_time,toString(toDateTime(dt),'America/New_York') as NY_time;
?
SELECT?
? ? formatDateTime(now(), '%F %T') AS dt,
? ? toString(toDateTime(dt), 'Asia/Shanghai') AS BJ_time,
? ? toString(toDateTime(dt), 'America/New_York') AS NY_time
?
┌─dt──────────────────┬─BJ_time─────────────┬─NY_time─────────────┐
│ 2020-07-12 00:13:29 │ 2020-07-12 00:13:29 │ 2020-07-11 12:13:29 │
└─────────────────────┴─────────────────────┴─────────────────────┘
?
1 rows in set. Elapsed: 0.006 sec.?
?
?
可以看到Clickhouse默認采用的系統(tǒng)的UTC
?
?
Clickhouse> select formatDateTime(now(),'%F %T') as dt,toString(toDateTime(dt,'UTC'),'Asia/Shanghai') as BJ_time,toTimeZone(toDateTime(dt,'UTC'),'Asia/Shanghai') as random_time,toString(toDateTime(dt),'Asia/Shanghai') SH_TIME,toTimeZone(toDateTime(dt),'Asia/Shanghai') SH_time,toTimeZone(toDateTime(dt,'America/New_York'), 'Asia/Hong_Kong') HK_time;
?
SELECT?
? ? formatDateTime(now(), '%F %T') AS dt,
? ? toString(toDateTime(dt, 'UTC'), 'Asia/Shanghai') AS BJ_time,
? ? toTimeZone(toDateTime(dt, 'UTC'), 'Asia/Shanghai') AS random_time,
? ? toString(toDateTime(dt), 'Asia/Shanghai') AS SH_TIME,
? ? toTimeZone(toDateTime(dt), 'Asia/Shanghai') AS SH_time,
? ? toTimeZone(toDateTime(dt, 'America/New_York'), 'Asia/Hong_Kong') AS HK_time
?
┌─dt──────────────────┬─BJ_time─────────────┬─────────random_time─┬─SH_TIME─────────────┬─────────────SH_time─┬─────────────HK_time─┐
│ 2020-07-12 00:27:25 │ 2020-07-12 08:27:25 │ 2020-07-12 08:27:25 │ 2020-07-12 00:27:25 │ 2020-07-12 00:27:25 │ 2020-07-12 12:27:25 │
└─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┘
?
1 rows in set. Elapsed: 0.007 sec.?
?
可以看到toTimeZone,與toString 的功能很像
?
?
Clickhouse> select formatDateTime(now(),'%F %T') as dt,toTypeName(toString(toDateTime(dt),'Asia/Shanghai')) SH_TIME,toTypeName(toTimeZone(toDateTime(dt),'Asia/Shanghai')) SH_time,toTypeName(toTimeZone(toDateTime(dt,'America/New_York'), 'Asia/Hong_Kong')) HK_time;
?
SELECT?
? ? formatDateTime(now(), '%F %T') AS dt,
? ? toTypeName(toString(toDateTime(dt), 'Asia/Shanghai')) AS SH_TIME,
? ? toTypeName(toTimeZone(toDateTime(dt), 'Asia/Shanghai')) AS SH_time,
? ? toTypeName(toTimeZone(toDateTime(dt, 'America/New_York'), 'Asia/Hong_Kong')) AS HK_time
?
┌─dt──────────────────┬─SH_TIME─┬─SH_time───────────────────┬─HK_time────────────────────┐
│ 2020-07-12 00:29:43 │ String ?│ DateTime('Asia/Shanghai') │ DateTime('Asia/Hong_Kong') │
└─────────────────────┴─────────┴───────────────────────────┴────────────────────────────┘
?
1 rows in set. Elapsed: 0.002 sec.?
toTimeZone函數(shù)可以實現(xiàn)時區(qū)轉(zhuǎn)換,通過toTypeName還可以獲知字段類型,以及該字段對應(yīng)的時區(qū)。
相關(guān)的函數(shù)
————————————————
版權(quán)聲明:本文為CSDN博主「vkingnew」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/vkingnew/article/details/107227037

總結(jié)

以上是生活随笔為你收集整理的Clickhouse 时区的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。