Skip to content

DateTime Commands ​

System time and timezone management is critical for Zal Ultra. Incorrect time causes authentication failures, billing issues, and log inconsistencies.

🟡 LOW RISK

Most datetime commands are safe for viewing. Only timezone changes require caution.


Table of Contents ​

  1. View Date & Time
  2. Timezone Management
  3. NTP Synchronization
  4. Hardware Clock
  5. Troubleshooting

View Date & Time ​

Show Current Date and Time ​

bash
date

Output: Sat Mar 8 17:30:45 UTC 2025

Show Date in Specific Format ​

bash
# ISO format
date +"%Y-%m-%d %H:%M:%S"

# Custom format
date +"%d/%m/%Y %I:%M %p"

# Unix timestamp
date +%s

Show Current Timezone ​

bash
timedatectl

Example Output:

               Local time: Sat 2025-03-08 17:30:45 UTC
           Universal time: Sat 2025-03-08 17:30:45 UTC
                 RTC time: Sat 2025-03-08 17:30:45
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Show UTC Time ​

bash
date -u

Show Timezone Abbreviation ​

bash
date +%Z

Timezone Management ​

List Available Timezones ​

bash
timedatectl list-timezones

Search for Timezone ​

bash
timedatectl list-timezones | grep -i asia
timedatectl list-timezones | grep -i dhaka
timedatectl list-timezones | grep -i karachi

Common Timezones ​

RegionTimezone
BangladeshAsia/Dhaka
PakistanAsia/Karachi
IndiaAsia/Kolkata
UAEAsia/Dubai
UKEurope/London
US EastAmerica/New_York
US WestAmerica/Los_Angeles

Set Timezone ​

🟠 CAUTION

Changing timezone affects all timestamps in logs and may cause temporary confusion in billing/reports.

bash
sudo timedatectl set-timezone Asia/Dhaka

Verify Timezone Change ​

bash
timedatectl
date

bash
sudo ln -sf /usr/share/zoneinfo/Asia/Dhaka /etc/localtime

NTP Synchronization ​

Check NTP Status ​

bash
timedatectl status

Look for: System clock synchronized: yes

Enable NTP ​

bash
sudo timedatectl set-ntp true

Disable NTP ​

bash
sudo timedatectl set-ntp false

Check NTP Service ​

bash
sudo systemctl status systemd-timesyncd

Force Time Sync ​

bash
sudo systemctl restart systemd-timesyncd

Using chrony (Alternative NTP) ​

bash
# Install chrony
sudo apt install chrony

# Check status
chronyc tracking

# Force sync
sudo chronyc makestep

# View sources
chronyc sources

Hardware Clock ​

Show Hardware Clock Time ​

bash
sudo hwclock --show

Sync System Time to Hardware Clock ​

bash
sudo hwclock --systohc

Sync Hardware Clock to System Time ​

bash
sudo hwclock --hctosys

Manual Time Setting ​

🟠 NOT RECOMMENDED

Only use if NTP is unavailable. Manual time will drift.

Set Date and Time Manually ​

bash
# Disable NTP first
sudo timedatectl set-ntp false

# Set date and time
sudo timedatectl set-time "2025-03-08 17:30:00"

# Or using date command
sudo date -s "2025-03-08 17:30:00"

Troubleshooting ​

Time Drifting ​

bash
# Check NTP sync status
timedatectl status

# Restart NTP service
sudo systemctl restart systemd-timesyncd

# Force immediate sync
sudo systemctl stop systemd-timesyncd
sudo ntpdate pool.ntp.org
sudo systemctl start systemd-timesyncd

Wrong Timezone in PHP ​

bash
# Check PHP timezone
php -i | grep timezone

# Set in php.ini
sudo nano /etc/php/8.3/fpm/php.ini
# Add: date.timezone = Asia/Dhaka

sudo systemctl restart php8.3-fpm

Wrong Timezone in MySQL ​

sql
-- Check MySQL timezone
SELECT @@global.time_zone, @@session.time_zone;

-- Set timezone
SET GLOBAL time_zone = '+06:00';

Or in MySQL config:

bash
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# Add: default-time-zone = '+06:00'

sudo systemctl restart mysql

Laravel Timezone ​

Check .env file:

bash
APP_TIMEZONE=Asia/Dhaka

Check config/app.php:

php
'timezone' => env('APP_TIMEZONE', 'UTC'),

Quick Reference Card ​

ActionCommand
Show date/timedate
Show timezone infotimedatectl
List timezonestimedatectl list-timezones
Set timezonesudo timedatectl set-timezone Asia/Dhaka
Enable NTPsudo timedatectl set-ntp true
Check NTP statustimedatectl status
Force syncsudo systemctl restart systemd-timesyncd
Hardware clocksudo hwclock --show
UTC timedate -u
Unix timestampdate +%s

www.onezeroart.com