Linux Command Check Current Time
- Formatted time
- HH:MM:SS
- Result
- Hours (0-23)
- 14 h
- You entered
- Minutes (0-59)
- 23 min
- You entered
To check the current time in Linux, type date in a terminal and press Enter. This displays the system date and time in the default format, such as Tue Apr 8 14:23:45 UTC 2025. The date command is built into most Linux distributions and requires no installation.
Formula
The calculator above converts a given hour, minute, and second into the total seconds elapsed since midnight and formats it as HH:MM:SS. The formula is:
total_seconds = (hours × 3600) + (minutes × 60) + seconds
Where:
- hours – the hour part of the time (0–23)
- minutes – the minute part (0–59)
- seconds – the second part (0–59)
This is the standard way to represent time as a single number, often used in scripting and logging.
Worked Example
Using the default values from the calculator (14 hours, 23 minutes, 45 seconds):
- Convert hours to seconds: 14 × 3600 = 50,400
- Convert minutes to seconds: 23 × 60 = 1,380
- Add all parts: 50,400 + 1,380 + 45 = 51,825 seconds
So the total seconds since midnight is 51,825, and the formatted time is 14:23:45.
Understanding the date Command
The date command reads the system clock, which the Linux kernel maintains. When you run it without options, it prints the current date and time in a human-readable format. The default output includes the day of the week, month, day, time (with seconds), timezone, and year. The exact format can vary slightly between distributions, but the information is the same.
You can also use date to display the time in UTC (Coordinated Universal Time) by adding the -u option: date -u. This is useful when you work with servers or logs that use UTC to avoid timezone confusion.
Formatting the Output
Often you need the time in a specific format for scripts or logs. The date command supports format specifiers that start with %. For example:
date +"%H:%M:%S"– shows only the time in 24-hour format (e.g., 14:23:45)date +"%Y-%m-%d"– shows the date in YYYY-MM-DD format (e.g., 2025-04-08)date +"%s"– shows the Unix epoch time (seconds since January 1, 1970)
These specifiers are documented in the date manual page (man date). You can combine them in any order, and include literal text by quoting the format string.
Time Zones and the TZ Variable
Linux uses the TZ environment variable to determine the timezone for displaying time. By default, this is set in system configuration files like /etc/timezone or via the timedatectl command. To see the current time in a different timezone without changing the system setting, you can prefix the command with TZ:
TZ='America/New_York' date
TZ='Asia/Tokyo' date
This is helpful when coordinating with people in other regions or when checking logs from servers in different timezones.
Common Problems and Solutions
If the date command shows the wrong time, the system clock may be off. This can happen if the hardware clock (RTC) is set to local time instead of UTC, or if NTP (Network Time Protocol) synchronization is disabled. To fix it:
- Check the current time with
dateanddate -u. - Use
timedatectlto view system time settings (on systemd-based systems). - Enable automatic time sync with
sudo timedatectl set-ntp true. - If NTP is already on, force a sync with
sudo systemctl restart systemd-timesyncd(or usentpdateon older systems).
Another common issue is that the date command is not found, which is rare because it is part of the coreutils package. If that happens, install coreutils using your package manager (e.g., sudo apt install coreutils on Debian/Ubuntu).
Alternatives to date
While date is the standard, there are other ways to get the current time:
timedatectl– shows more detailed system clock and timezone information.hwclock– reads the hardware clock (RTC). This shows the time stored on the motherboard, which may differ from the system time.uptime -s– shows when the system was booted, not the current time, but useful for reference.
For scripting, you can also use echo $(date) or capture the output in a variable, but the command itself remains the same.
Frequently Asked Questions
How do I get the current time in milliseconds?
Use the %s specifier with milliseconds appended manually, or use date +"%s%3N" to get milliseconds since the Unix epoch. The %N specifier gives nanoseconds, but you need to truncate to 3 digits for milliseconds.
Why does date show a different time than my phone?
Your phone likely uses network time and your local timezone. Linux may be set to a different timezone, or the system clock may be incorrect. Check your timezone with timedatectl and ensure NTP is enabled.
Can I display the time in 12-hour format?
Yes, use date +"%I:%M:%S %p" – %I gives the hour in 12-hour format, and %p shows AM or PM.
How do I set the time manually?
Use sudo date -s "2025-04-08 14:30:00" to set the system time. However, it is recommended to use NTP for accuracy.
What is the difference between date and hwclock?
date reads the Linux system clock, which is maintained by the kernel and can be adjusted by NTP. hwclock reads the hardware clock (RTC) on the motherboard, which persists when the computer is off. The two can differ, especially if the RTC is set to local time while the system uses UTC.
Related
Formula used
in t | Hours (0-23) | h | 14 | 0 in m | Minutes (0-59) | min | 23 | 0 in s | Seconds (0-59) | s | 45 | 0 out total | Seconds since midnight | s | (t*3600)+(m*60)+s | 0 out hhmmss | Formatted time | HH:MM:SS | (t*3600)+(m*60)+s | time
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.