Linux 操作當前時間

2021-09-06 14:10:58 字數 701 閱讀 7648

1. 檢視當前時區

命令 : "date -r"

2. 修改設定linux伺服器時區

方法 a

命令 : "tzselect"

方法 b 僅限於redhat linux 和 centos

命令 : "timeconfig"

方法 c 適用於debian

命令 : "dpkg-reconfigure tzdata"

3. 複製相應的時區檔案,替換系統時區檔案;或者建立鏈結檔案

cp /usr/share/zoneinfo/$主時區/$次時區 /etc/localtime

例如:在設定中國時區使用亞洲/上海(+8)

cp /usr/share/zoneinfo/asia/shanghai /etc/localtime

1. 檢視時間和日期

命令 : "date"

2.設定時間和日期

例如:將系統日期設定成2023年11月3日的命令

命令 : "date -s 11/03/2009"

將系統時間設定成下午5點55分55秒的命令

命令 : "date -s 17:55:55"

3. 將當前時間和日期寫入bios,避免重啟後失效

命令 : "hwclock -w"

注:date

不加引數可以直接看到當前日期時間

cal不加引數可以直接看到本月月曆

js操作當前時間

1.獲取當前時間 var now new date var fullyear now.getfullyear 獲取格式為20190809 var year now.getyear 獲取年份 var month now.getmonth 獲取月份從0開始,1月為0,8月為7 var day now.g...

Linux獲取當前時間

1.linux下與時間有關的結構體 struct timeval 其中tv sec是由凌晨開始算起的秒數,tv usec則是微秒 10e 6 second struct timezone tv minuteswest是格林威治時間往西方的時差,tv dsttime則是時間的修正方式。struct t...

Linux 檢視當前時間

1.檢視當前時區 命令 date r 2.修改設定linux伺服器時區 方法 a 命令 tzselect 方法 b 僅限於redhat linux 和 centos 命令 timeconfig 方法 c 適用於debian 命令 dpkg reconfigure tzdata 3.複製相應的時區檔案...