On Ubuntu, the system timezone is set during the installation process, but can be changed later.

在Ubuntu上,系统时区是在安装过程中设置的,但以后可以更改。

Configuring the appropriate timezone is important for a lot of us, so let us find out how we can change the timezone on our Ubuntu 18.04 system.

对我们中的大多数人而言,配置适当的时区很重要,因此让我们了解如何在Ubuntu 18.04系统上更改时区。



方法1.使用timedatectl命令 (Approach 1. Using timedatectl command)

We can use the timedatectl command to display and set the current system’s time and timezone.

我们可以使用timedatectl命令来显示和设置当前系统的时间和时区。


timedatectl
Ubuntu View Timezone
Ubuntu View时区

As you can observe, here, the timezone is currently set to UTC.

如您所见,此处的时区当前设置为UTC

Let’s get this changed to IST (GST +5:30) using a few steps!

让我们通过几个步骤将其更改为IST (GST +5:30)!

查找我们所需时区的时区格式 (Find the timezone format for our required timezone)

We need to find out the format for the timezone you want to use. The timezone naming convention usually uses a “Region/City” format.

我们需要找出您要使用的时区的格式。 时区命名约定通常使用“ Region / City ”格式。

To list all available time zones, we can use timedatectl along with the list-timezones option.

要列出所有可用时区,我们可以使用timedatectl以及list-timezones选项。


timedatectl list-timezones

We will get an output like this, showing the long name format for all available timezones.

我们将得到这样的输出,显示所有可用时区的长名称格式。

Ubuntu View Timezone Options
Ubuntu View时区选项

Let us find out the required format for our necessary timezone, which we want to find; IST, in my case. It is in the Kolkata zone, so let’s grep for Kolkata.

让我们找出我们想要的时区所需的格式; IST ,就我而言。 它是在加尔各答区,让我们对加尔各答的grep。


timedatectl list-timezones | grep Kolkata
Ubuntu Search Ist Format
Ubuntu搜索Ist格式

Now we have identified our timezone format. We just need to set it now!

现在,我们确定了时区格式。 我们只需要立即设置!

设置时区 (Set the timezone)

Use the below command to change the timezones, as root.

使用以下命令以root身份更改时区。


sudo timedatectl set-timezone your_time_zone

In my case, it is Asia/Kolkata, so the command will be

在我的情况下,它是Asia / Kolkata ,所以命令将是


sudo timedatectl set-timezone Asia/Kolkata

Alternatively, we can also directly set the timezone to its abbreviated format (IST, in my case)

另外,我们也可以将时区直接设置为缩写格式(在我的情况下为IST


sudo timedatectl set-timezone IST
Ubuntu Change Timezone Successful
Ubuntu更改时区成功

If this is successful, you will see the system time in terms of your timezone, and the timezone has been successfully updated!

如果成功,则将以时区显示系统时间,并且时区已成功更新!

But even if the above method didn’t work, we have some alternatives. So if you’ve configured timezone successfully using timedatectl, the rest of the article is not required. But otherwise, let’s keep reading.

但是,即使上述方法无效,我们也有其他选择。 因此,如果您已经成功地使用timedatectl配置了时区,则本文的其余部分不是必需的。 但是,否则,让我们继续阅读。



方法2。重新配置时区数据 (Approach 2. Reconfigure Timezone Data)

Suppose the above method didn’t work, we can use dpkg to reconfigure our timezone data and set the desired timezone.

假设上述方法无效,我们可以使用dpkg重新配置时区数据并设置所需的时区。


sudo dpkg-reconfigure tzdata

We will now get a menu that allows us to reconfiguring our timezone.

现在,我们将获得一个菜单,该菜单使我们可以重新配置时区。

Ubuntu Reconfigure Timezone
Ubuntu重新配置时区

Now, you can use the graphical menu to successfully update your timezone!

现在,您可以使用图形菜单成功更新您的时区!



方法3.更改/ etc / localtime文件 (Approach 3. Change the /etc/localtime file)

方法1:使用区域时区详细信息 (Method 1: Using Region Timezone details)

Another way of changing the timezone would be to edit the localtime file manually.

更改时区的另一种方法是手动编辑localtime文件。

Information about the timezone is located at /etc/localtime. We can manually modify that file to our desired timezone, which is located at /usr/share/zoneinfo/.

有关时区的信息位于/etc/localtime 。 我们可以将该文件手动修改为所需的时区,该时区位于/usr/share/zoneinfo/

The zoneinfo directory contains a list of Regions of interest. Select your region. (For IST, the region is Asia)

zoneinfo目录包含感兴趣的区域列表。 选择您的地区。 (对于IST,该地区是亚洲

Ubuntu Zoneinfo Files
Ubuntu Zoneinfo文件
Ubuntu Zoneinfo Asia
Ubuntu Zoneinfo亚洲

Now, simply copy the Kolkata timezone file to /etc/localtime.

现在,只需将加尔各答时区文件复制到/etc/localtime


sudo cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

Restart the machine to apply your changes.

重新启动机器以应用您的更改。

With this, we have now updated our timezone successfully!

这样,我们现在已经成功更新了时区!

方法2:直接使用时区 (Method 2: Using Timezones directly)

We can also directly perform a symbolic link between the details of the Timezone file and /etc/localtime, located at /usr/share/zoneinfo/TIMEZONE, where TIMEZONE is your required timezone. In my case, it is IST.

我们还可以直接在位于/usr/share/zoneinfo/TIMEZONE的Timezone文件的详细信息和/etc/localtime之间执行符号链接,其中TIMEZONE是您所需的时区。 就我而言,它是IST


sudo ln -sf /usr/share/zoneinfo/IST /etc/localtime

Again, restart your machine to apply the changes.

再次,重新启动计算机以应用更改。

Now, we have shown you different methods for updating your timezone!

现在,我们向您展示了更新时区的不同方法!



结论 (Conclusion)

In this tutorial, we showed how you can change the timezone of your Ubuntu 18.04 system using various methods.

在本教程中,我们展示了如何使用各种方法来更改Ubuntu 18.04系统的时区。



后记:建议 (Afterword: Recommendations)

While we have shown different approaches, usually, the recommended method depends on your background:

尽管我们展示了不同的方法,但是通常推荐的方法取决于您的背景:

  • If you are a new user of Ubuntu coming from Windows, it is recommended that you use the GUI mode of changing the timezone, using dpkg, since it is user-friendly.如果您是Windows的Ubuntu新用户,建议您使用dpkg来更改时区的GUI模式,因为它是用户友好的。
  • On the other hand, you have experience with Linux previously, but not using Ubuntu, you can manually change /etc/localtime.另一方面,您以前有使用Linux的经验,但是没有使用过Ubuntu,可以手动更改/etc/localtime
  • Otherwise, if you are a day to day user of Ubuntu, timedatectl is your best bet!否则,如果您是Ubuntu的日常用户,那么timedatectl是您的最佳选择!

Hope you found your answer by reading this tutorial!

希望您通过阅读本教程找到答案!



翻译自: https://www.journaldev.com/33989/change-timezone-in-ubuntu

在Ubuntu 18.04中更改时区相关推荐

  1. 在Ubuntu 18.04中安装JDK 8

    在Ubuntu 18.04中安装JDK 8 安装 Oracle JDK Webupd8 Team维护一个PPA存储库,其中包含适用于所有当前Ubuntu版本的Oracle Java 8安装程序脚本. ...

  2. linux mint 18.3浏览器,在Linux Mint 19/Ubuntu 18.04中安装Tor Browser浏览器的方法

    本文介绍在Linux Mint 19/Ubuntu 18.04系统中安装Tor Browser浏览器的方法,本文不使用Tor的默认Ubuntu存储库,因为它们包含旧版本的Tor. 一.添加Tor存储库 ...

  3. linux紧急救援模式,如何在 Ubuntu 18.04 中启动到救援模式或紧急模式

    正如你可能已经知道的那样,运行级别 在许多最近的 Linux 发行版(如 RHEL 7 和 Ubuntu 16.04 LTS)中被 systemd 的目标 替换.在这个简短的教程中,我们将看到如何启动 ...

  4. linux图片编辑工具,如何在Ubuntu 18.04中安装Pinta图像编辑器

    在本文中,我们将学习如何在Ubuntu 18.04中安装Pinta图像编辑器. Pinta是一个免费的开源GNOME绘画应用程序,可用于编辑图像和绘画. Pinta由Jonathan Post于201 ...

  5. 在 Ubuntu 18.04 中配置静态 IP 地址及灵活切换IP的办法

    Ubuntu 18.04 使用 Netplan 来配置 IP 地址,Netplan 是一个新的命令行网络配置工具. 新的 IP 配置方法不会再用到 /etc/network/interfaces 这个 ...

  6. 解决Ubuntu 18.04中无法播放MP4文件的问题

    遇到的问题 在Ubuntu 18.04中无法播放MP4文件,提示播放该文件需要H.264(主配置文件)解码器. 测试机型:联想邵阳E42 测试时间:2020年9月5日 测试系统:18.04 解决方法 ...

  7. ubuntu实现中文输入法_在Ubuntu 18.04中设置中文输入法

    (本文系搬运,图片来自网络,侵删.英语为自己翻译,水平有限,欢迎指点) Setup Chinese Input Method in Ubuntu 18.04 Fri Oct 20 2017 The o ...

  8. Linux终端文件夹管理员,如何在Ubuntu 18.04中以管理员权限打开文件和文件夹

    本文向你介绍在Ubuntu 18.04中以管理员权限打开文件和文件夹. 与 Windows 中的资源管理器一样,在 Ubuntu 系统的 Nautilus 文件管理器中,您也可以查看到系统中的所有文件 ...

  9. linux 切换到最左边,Ubuntu 18.04中使用Mac OS风格的Dock启动器替换左侧面板

    对于那些想要改变Ubuntu 18.04左侧面板"Ubuntu Dock"的外观和感觉的人来说,Dash to Dock是一个Gnome扩展,用Mac OS风格的Dock应用程序启 ...

最新文章

  1. java导出excel(easypoi)
  2. vue组件一直注册不了_Vue注册组件命名时不能用大写的原因浅析
  3. androidstudio 常用快捷键
  4. Python 常用排序Demo|冒、插、快、希等入门算法
  5. 非递归实现二叉树(前序,中序,后序)c/c++实现
  6. python求超级素数代码_C语言求超级素数
  7. python里else中文意思_Python循环语句中else的用法总结
  8. 风险评估资产重要性识别_什么是风险分析,如何识别和评估风险?
  9. 构造器2(Java)
  10. android反调试之父子调试
  11. 从客户需求开始你的供应链管理战略
  12. pythonexcel源码_Python对Excel操作详解_Python教程
  13. 2019软科【世界一流计算机学科排名】公布!
  14. uni-app生成pdf,依赖html2canvas和jspdf
  15. 模拟电子技术(学习笔记 1)
  16. 3、RDA8910(4GCAT1)CSDK二次开发:GPIO输入详解
  17. 新一代最强开源UI自动化测试神器 Playwright - 元素定位
  18. SN74LS148优先编码器的级联使用
  19. dfs python
  20. linux 扫描磁盘柜,Linux下做磁盘阵列和各种热备份

热门文章

  1. JVM学习之GC参数设置
  2. CSS背景图像的简单响应
  3. EXT.NET高效开发(二)——封装函数
  4. Spring.NET企业架构实践之 Nhibernate + WCF + ASP.NET MVC + NVelocity 对PetShop4.0重构(三)——持久层...
  5. 笔者认为,中国的互联网行业需要真正的CEO
  6. [转载] python 去除字符串中指定字符
  7. mysql cmmand not found
  8. 接口测试系列:工作中所用(十:配置文件的读写操作 configparser模块)
  9. Oracle 04-Oracle创建数据库
  10. 虚拟机安装ubuntu18.04及其srs服务器的搭建