Appearance
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
View Date & Time
Show Current Date and Time
bash
dateOutput: 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 +%sShow Current Timezone
bash
timedatectlExample 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: noShow UTC Time
bash
date -uShow Timezone Abbreviation
bash
date +%ZTimezone Management
List Available Timezones
bash
timedatectl list-timezonesSearch for Timezone
bash
timedatectl list-timezones | grep -i asia
timedatectl list-timezones | grep -i dhaka
timedatectl list-timezones | grep -i karachiCommon Timezones
| Region | Timezone |
|---|---|
| Bangladesh | Asia/Dhaka |
| Pakistan | Asia/Karachi |
| India | Asia/Kolkata |
| UAE | Asia/Dubai |
| UK | Europe/London |
| US East | America/New_York |
| US West | America/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/DhakaVerify Timezone Change
bash
timedatectl
dateSet Timezone via Symlink (Alternative)
bash
sudo ln -sf /usr/share/zoneinfo/Asia/Dhaka /etc/localtimeNTP Synchronization
Check NTP Status
bash
timedatectl statusLook for: System clock synchronized: yes
Enable NTP
bash
sudo timedatectl set-ntp trueDisable NTP
bash
sudo timedatectl set-ntp falseCheck NTP Service
bash
sudo systemctl status systemd-timesyncdForce Time Sync
bash
sudo systemctl restart systemd-timesyncdUsing chrony (Alternative NTP)
bash
# Install chrony
sudo apt install chrony
# Check status
chronyc tracking
# Force sync
sudo chronyc makestep
# View sources
chronyc sourcesHardware Clock
Show Hardware Clock Time
bash
sudo hwclock --showSync System Time to Hardware Clock
bash
sudo hwclock --systohcSync Hardware Clock to System Time
bash
sudo hwclock --hctosysManual 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-timesyncdWrong 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-fpmWrong 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 mysqlLaravel Timezone
Check .env file:
bash
APP_TIMEZONE=Asia/DhakaCheck config/app.php:
php
'timezone' => env('APP_TIMEZONE', 'UTC'),Quick Reference Card
| Action | Command |
|---|---|
| Show date/time | date |
| Show timezone info | timedatectl |
| List timezones | timedatectl list-timezones |
| Set timezone | sudo timedatectl set-timezone Asia/Dhaka |
| Enable NTP | sudo timedatectl set-ntp true |
| Check NTP status | timedatectl status |
| Force sync | sudo systemctl restart systemd-timesyncd |
| Hardware clock | sudo hwclock --show |
| UTC time | date -u |
| Unix timestamp | date +%s |
