Change time format linux

How to Change Time (Clock) Format on Ubuntu Linux

This article explains the steps one can take to change the time (clock) to 12h or 24h format in Ubuntu Linux.

Ubuntu Linux default displays the system time in a 24-hour or military time format. If you prefer to read your system clock in a 12-hour format, continue below to learn how to change that.

Whatever time or clock format you choose will appear on the Top bar. It may also appear in applications and documents you create unless you override the format in individual programs.

Choose whether the clock displays 12h or 24h format

As mentioned above, if Ubuntu Linux displays its system clock in a 24-hour format and you want to change it to a 12-hour format, the steps below show you how.

Ubuntu Linux has a centralized location for the majority of its settings. From system configurations to creating new users and updating, all can be done from the System Settings panel.

To get to System Settings , open the Activities overview and start typing Settings .

Alternatively, click on the System menu at the top-right corner of the top bar on your desktop.

On the System menu, select Settings, as highlighted below.

ubuntu linux system menu settings button

In the Settings app, select Date & Time on the left menu.

Ubuntu Linux date and time pane

On the System Settings -> Date & Time settings panel, next to the Time Format section, use the drop-down option to choose a format:

Ubuntu Linux date and time pane time format options

  • 24-hour
  • AM/PM

The option you choose will automatically apply to your desktop.

Change system time format using the command terminal console

Another way to change the system clock or time format is via the command line terminal console.

Like many other Linux distributions, most system settings changes are done using the command terminal. Naturally, most Linux users should be familiar with the command terminal.

First, open the Terminal app in Ubuntu Linux.

You can do that by pressing the Super key (or Windows key) to show the Overview screen. Then use the search box to search for ‘Terminal. ‘

Select the Terminal app to launch.

Alternatively, press the keyboard shortcut ( CTRL + ALT + T ) on your keyboard to launch the Terminal app.

When the Terminal app opens, type the commands below to display a 12-hour clock format.

gsettings set org.gnome.desktop.interface clock-format 12h

To reverse and use a 24-hour clock format, run the commands below.

gsettings set org.gnome.desktop.interface clock-format 24h

Change system time format using the Dconf Editor

You can also use Dconf Editor to make typical system changes if you can’t use the command Terminal app.

Читайте также:  Astra linux сеть недоступна

If you are familiar with Windows, you know about Windows Registry Editor.

Ubuntu Linux doesn’t have a registry database to configure hidden system settings. Howerver, Ubuntu Linux uses the Dconf Editor tool to change low-level system configurations and settings.

You can call it a Ubuntu Linux Registry Editor because it provides similar functionality without a massive Windows system database.

To use Dconf Editor, you must first install it since it doesn’t come with Ubuntu Linux.

Read the post below to learn how to install software on Ubuntu Linux.

In the Ubuntu Software app, search for Dconf Editor to install.

After installing and launching the Dconf Editor app, navigate to the path below:

org -> gnome -> desktop -> interface -> clock-format

On the Clock-Format Dconf settings pane, toggle the “Use default value” button to the Off position.

Then use the Custom value option to choose a 12h or 24h time format.

Ubuntu Linux date and time pane time format options via dconf

This post showed you how to change the time or clock format on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.

Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Источник

Установить 24-часовой формат даты linux

Друзья, всем привет! Не могу найти информацию о том, как установить 24-часовой формат даты на сервере linux (Ubuntu). При вводе в консоль команды date выводится Tue Jan 10 07:52:54 PM +05 2023 А мне нужно, чтобы было в 24-часовом формате. Не 07:52, а 19:52

я бы скорее предположил, что вопрос вообще в настройке более подходящей локали в системе, а не только date. LC_TIME в частности

+05 — а вот этот фрагмент весьма странно выглядит. согласно man-у, /bin/date выдаёт подобный фрагмент для формата %. z , но я такого фрагмента в /usr/share/i18n/locales/ не нашёл. было бы интересно взглянуть на вывод программы locale (без аргументов) из этой вашей системы. приложите его, пожалуйста, к тексту вопроса, нажав править.

1 ответ 1

вообще программа /bin/date берёт информацию о формате вывода из базы данных локалей (locales). текущие установки локали можно посмотреть, вызвав без аргументов программу:

а с помощью вот такого вызова можно узнать формат для текущей локали:

вот этот кусочек (из вашего примера) — 07:52:54 PM — программой /bin/date выводится для формата %r (см. $ man date : «locale’s 12-hour clock time (e.g., 11:11:04 PM)»).

вы можете увидеть упоминание этого формата, запустив предыдущую команду.

переопределить же формат даты/времени можно переменной окружения LC_TIME . примеры:

$ env -i LC_TIME=ru_RU.utf8 /bin/date Вт 10 янв 2023 19:15:48 MSK $ env -i LC_TIME=en_US.utf8 /bin/date Tue 10 Jan 2023 07:15:59 PM MSK 

выберите подходящую локаль (не содержащую в d_t_fmt формата %r ). их вообще много, см. вывод:

$ grep -r d_t_fmt /usr/share/i18n/locales/ | grep -v '%r' 

вообще даже ru_RU подойдёт под вашу задачу:

$ env -i LC_TIME=ru_RU.utf8 /bin/date Вт 10 янв 2023 19:26:29 MSK 

но можно и на какой-нибудь англоязычной остановиться:

$ grep -r d_t_fmt /usr/share/i18n/locales/ | grep -v '%r' | grep en_ /usr/share/i18n/locales/en_IL:d_t_fmt "%a %d %b %Y %T" /usr/share/i18n/locales/en_ZM:d_t_fmt "%a %d %b %Y %T %Z" /usr/share/i18n/locales/en_NG:d_t_fmt "%a %d %b %Y %T" /usr/share/i18n/locales/en_IN:d_t_fmt "%A %d %B %Y %I:%M:%S %p" /usr/share/i18n/locales/en_AG:d_t_fmt "%a %d %b %Y %T %Z" /usr/share/i18n/locales/en_GB:d_t_fmt "%a %d %b %Y %T %Z" /usr/share/i18n/locales/en_DK:d_t_fmt "%Y-%m-%dT%T %Z" /usr/share/i18n/locales/en_PH:d_t_fmt "%A, %d %B, %Y %I:%M:%S %p" /usr/share/i18n/locales/en_AU:d_t_fmt "%a %d %b %Y %T" /usr/share/i18n/locales/en_HK:d_t_fmt "%A, %B %d, %Y %p%I:%M:%S" /usr/share/i18n/locales/en_IE:d_t_fmt "%a %d %b %Y %T" /usr/share/i18n/locales/en_ZA:d_t_fmt "%a %d %b %Y %T" /usr/share/i18n/locales/en_NZ:d_t_fmt "%a %d %b %Y %T" 

en_GB (great britain), или en_NZ (new zealand), или ещё какую-нибудь:

$ env -i LC_TIME=en_GB.utf8 /bin/date Tue 10 Jan 19:30:10 MSK 2023 $ env -i LC_TIME=en_NZ.utf8 /bin/date Tue 10 Jan 2023 19:30:25 MSK 

но тут ещё такая засада, что если вдруг определена переменная LC_ALL (а она часто бывает определена), то значения других «локале-задающих» переменных LC_* игнорируются. поэтому, если она в вашем окружении определена, то менять надо уже её, а не LC_TIME .

Читайте также:  Open tor in linux

ах, да, совсем забыл написать про то, как менять. если у вас debian-подобный дистрибутив, то вручную подправить можно где-то в районе /etc/default/locale , ну или совсем уж по-простому:

$ sudo dpkg-reconfigure locales 

в других дистрибутивах смотрите документацию к ним.

Источник

Linux: set date through command line

You can use e.g. date —set=’-2 years’ to set the clock back two years, leaving all other elements identical. You can change month and day of month the same way. I haven’t checked what happens if that calculation results in a datetime that doesn’t actually exist, e.g. during a DST switchover, but the behaviour ought to be identical to the usual «set both date and time to concrete values» behaviour.

Assuming you’re trying to set the date to the current time, you could do sudo ntpd -gq to have the system update automatically using the ntp service.

7 Answers 7

Run that as root or under sudo . Changing only one of the year/month/day is more of a challenge and will involve repeating bits of the current date. There are also GUI date tools built in to the major desktop environments, usually accessed through the clock.

To change only part of the time, you can use command substitution in the date string:

will change the date, but keep the time. See man date for formatting details to construct other combinations: the individual components are %Y , %m , %d , %H , %M , and %S .

There’s no option to do that. You can use date -s «2014-12-25 $(date +%H:%M:%S)» to change the date and reuse the current time, though.

@MichaelHomer @SHW it is possible to change only the date with a command like date -s 2018-01-01 . Someone shared this in an answer also: superuser.com/questions/870068/…

System time

You can use date to set the system date. The GNU implementation of date (as found on most non-embedded Linux-based systems) accepts many different formats to set the time, here a few examples:

date -s 'next year' date -s 'last year' 
date -s 'last month' date -s 'next month' 
date -s 'next day' date -s 'tomorrow' date -s 'last day' date -s 'yesterday' date -s 'friday' 
date -s '2009-02-13 11:31:30' #that's a magical timestamp 

Hardware time

Читайте также:  Сменить пароль под linux

Now the system time is set, but you may want to sync it with the hardware clock:

Use —show to print the hardware time:

You can set the hardware clock to the current system time:

Or the system time to the hardware clock

Bonus points for illustrating the non-obvious ways you can set the date with examples and for pointing out the difference between the «system time» and the «hardware clock». Very helpful answer!

I think you confused hctosys and systohc. hctosys means «Set system time from hardware clock» and systohc means «Set hardware clock from system time».

The command to to change the system date is date .

There are two ways to call the date command(in Linux):

 date [OPTION]. [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 

Easy

The easiest way is to use date -s as it allows the use of simple relative dates

 $ date -s yesterday; date date: cannot set date: Operation not permitted Sat Jan 5 07:21:07 EST 2019 Sun Jan 6 07:21:07 EST 2019 

The date did not change because it was executed with a limited user $ . If you actually want the date changed, use root ( # ) or sudo:

 $ sudo date -s yesterday; date Sat Jan 5 07:21:07 EST 2019 Sat Jan 5 07:21:07 EST 2019 

So, changing any part of a relative date is as easy as naming it:

 $ date -s "5 years ago" Mon Jan 6 08:26:26 EST 2014 $ date -s "+6 months" Sat Jul 6 08:28:39 EDT 2019 $ date -s "+3 hours -13 minutes" Sun Jan 6 11:16:59 AST 2019 

Absolute dates are a bit more complex as they need more detail:

Or, you can use the date command twice:

replace any of the % by a valid value and the date will be set (only as root).

 $ date -s "$(date +'%Y-11-%d %H:%M:%S')" Wed Nov 6 08:37:15 EST 2019 

direct

The second date call form is used to directly change the system date.

 date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 

Will set the date to the 23th of November at 08h and 12min.

Try date as a limited user to see what it would do (without changing anything):

 $ date 11230812 date: cannot set date: Operation not permitted Sat Nov 23 08:12:00 EST 2019 

Or, if you actually want to change the date, as root:

 # date 11230812 # date Sat Nov 23 08:12:00 EST 2019 

Note that services like NTP or chrony will be affected. And, if restarted will reset the date back to the real one.

 $ date 1123081222 date: cannot set date: Operation not permitted Wed Nov 23 08:12:00 EST 2022 

Or a CCYY to set year and century:

 $ date 112308121982 date: cannot set date: Operation not permitted Tue Nov 23 08:12:00 EST 1982 

Источник

Оцените статью
Adblock
detector