Linux date Command

The date command in Linux is used to display or set the system date and time. It is a powerful utility that allows you to format the output in various ways.

Basic Syntax

date [OPTION]... [+FORMAT]

Common Options

Examples

1. Display the Current Date and Time

date

Output:

Tue Oct 10 14:30:00 UTC 2023

2. Display Only the Current Year

date +%Y

Output:

2023

3. Display Date in Custom Format

date "+%Y-%m-%d %H:%M:%S"

Output:

2023-10-10 14:30:00

4. Set the System Date and Time

sudo date -s "2023-10-10 14:30:00"

This command sets the system date and time to the specified value.

5. Display the Date in RFC 3339 Format

date --rfc-3339=seconds

Output:

2023-10-10 14:30:00+00:00

6. Display the Date in ISO 8601 Format

date --iso-8601=seconds

Output:

2023-10-10T14:30:00+00:00

7. Display the Date in UTC

date --utc

Output:

Tue Oct 10 14:30:00 UTC 2023

8. Display the Date in a Specific Time Zone

TZ="America/New_York" date

Output:

Tue Oct 10 10:30:00 EDT 2023

9. Display the Date in a Specific Format

date "+%A, %B %d, %Y"

Output:

Tuesday, October 10, 2023

Some Other method

0525115625.30

This Time formate is "mmddHHmmyy.ss"

Where:

To convert this format to a standard date format, you can use the date command with the -d option:

date -d "0525115625.30" +"%Y-%m-%d %H:%M:%S"

Output:

2025-05-25 11:56:25

Set Time zone

To set the time zone in Linux, you can use the timedatectl command. For example, to set the time zone to "America/New_York", you can use:

sudo timedatectl set-timezone America/New_York

To check the current time zone, you can use:

timedatectl

Output:

Local time: Tue 2023-10-10 14:30:00 UTC
Time zone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no

To list all available time zones, you can use:

timedatectl list-timezones

This will display a list of all available time zones. You can scroll through the list or use the grep command to filter for a specific time zone.

For example, to find all time zones that contain "Asia", you can use:

timedatectl list-timezones | grep Asia

This will display a list of all time zones that contain "Asia".

To set the time zone to a specific time zone, you can use the timedatectl set-timezone command followed by the name of the time zone. For example:

sudo timedatectl set-timezone Asia/Kolkata

This will set the time zone to "Asia/Kolkata".

To verify that the time zone has been set correctly, you can use the timedatectl command again:

timedatectl

Output:

Local time: Tue 2023-10-10 14:30:00 IST
Time zone: Asia/Kolkata (IST, +5:30)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no

Note: You may need to restart your system or log out and log back in for the changes to take effect.