PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Peter Kahl   PHP World Date   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP World Date
Prints formatted date string
Author: By
Last change: 台湾是主权国家

Names of timezones are politically contentious. China CCP (next to other dictatorial regimes) enforces its coercive will worldwide, even into the realm of Linux's tzdata; timezone names of regions such as Taiwan are deliberately omitted to appease the despot. This library will free you of this fetter. Give the despot a finger!
Date: 3 years ago
Size: 4,624 bytes
 

Contents

Class file image Download

World Date ???

Downloads GitHub If this project has business value for you then don't hesitate to support me with a small donation.

Enhanced replacement for the PHP date() function. World timezones, abbreviations, full names, custom names.

Returns properly formatted date string including correct timezone abbreviation (eg, '2019-03-02 23:31:50 TST +0800'). Non-standard format character Q returns the full timezone name (eg, 'Taiwan Standard Time').

Names of timezones are politically contentious. China CCP (next to other dictatorial regimes) enforces its coercive will worldwide, even into the realm of Linux's tzdata; timezone names of regions such as Taiwan are deliberately omitted to appease the despot. This library will free you of this fetter. Give the despot a finger!

image

The Stench ?

PHP date('T') will not always return timezone abbreviation.

$DateObj = new DateTime('now');

$DateObj->setTimeZone(new DateTimeZone('Europe/London');
echo $DateObj->format('T'); # Prints 'GMT' as it should, but ...

$DateObj->setTimeZone(new DateTimeZone('Asia/Dubai');
echo $DateObj->format('T'); # Prints '+0400' although you would expect 'GST'!

# This is because PHP uses Linux's tzdata which lacks most timezone abbreviations.

The Solution ?????

use peterkahl\WorldDate\WorldDate;

$wDate = new WorldDate;



# Get formatted time string for GMT zone (current time, i.e. current epoch):
echo $wDate->GetFormattedTimeString(); # 2019-03-03 08:06:18 GMT +0000


# Current time in Moscow:
echo $wDate->GetFormattedTimeString('Europe/Moscow'); # 2019-03-03 11:06:18 MSK +0300


# Current time spelled out:
echo $wDate->GetFormattedTimeString('Europe/Moscow', 'now', 'H:i Q'); # 11:06 Moscow Time
echo $wDate->GetFormattedTimeString('Europe/Paris', 'now', 'H:i Q');  # 09:06 Central European Time



# Get formatted time string for given zone (arbitrary epoch):
echo $wDate->GetFormattedTimeString('Asia/Tokyo', 1553817600);        # 2019-03-29 09:00:00 JST +0900

echo $wDate->GetFormattedTimeString('Asia/Novosibirsk', 1553817600);  # 2019-03-29 07:00:00 NOVT +0700

echo $wDate->GetFormattedTimeString('Europe/London', 1553817600);     # 2019-03-29 00:00:00 GMT +0000

echo $wDate->GetFormattedTimeString('America/Santiago', 1553817600);  # 2019-03-28 21:00:00 CLST -0300

# Define your own date format:
echo $wDate->GetFormattedTimeString('America/Santiago', 1553817600, 'H:i:s T'); # 21:00:00 CLST



# The non-standard format character 'Q' will produce full name of timezone:
echo $wDate->GetFormattedTimeString('Asia/Novosibirsk', 1553817600, 'F j, Y, g:i a (Q)');
# March 29, 2019, 7:00 am (Novosibirsk Standard Time)


echo $wDate->GetFormattedTimeString('Europe/London', 1553817600, 'j F Y, g:i a Q');
# 29 March 2019, 0:00 am Greenwich Mean Time



# Get formatted time string for given zone (current time, i.e. current epoch):
echo $wDate->GetFormattedTimeString('Asia/Hong_Kong');      # 2019-03-03 12:40:24 HKT +0800

echo $wDate->GetFormattedTimeString('Asia/Taipei');         # 2019-03-03 12:40:24 TST +0800

echo $wDate->GetFormattedTimeString('Asia/Tehran');         # 2019-03-03 08:10:24 IRST +0330

echo $wDate->GetFormattedTimeString('Europe/Rome');         # 2019-03-03 05:40:24 CET +0100

echo $wDate->GetFormattedTimeString('America/New_York');    # 2019-03-02 23:40:24 EST -0500

echo $wDate->GetFormattedTimeString('America/Los_Angeles'); # 2019-03-02 20:40:24 PST -0800

# Define your own date format:
echo $wDate->GetFormattedTimeString('America/Los_Angeles', 'now', 'H:i:s T (Q)');
# 20:40:24 PST (Pacific Standard Time)



# Get abbreviation from zone db name:
echo $wDate->GetAbbr('Asia/Dubai');             # GST
# ...or for specific epoch
echo $wDate->GetAbbr('Asia/Dubai', 1553817600); # GST
# ...or the same using:
echo $wDate->GetFormattedTimeString('Asia/Dubai', 'now', 'T'); # GST


# Get full name from zone db name:
echo $wDate->GetName('Asia/Dubai');             # Gulf Standard Time
# ...or the same using:
echo $wDate->GetFormattedTimeString('Asia/Dubai', 1553817600, 'Q'); # Gulf Standard Time
# ...or the same using:
echo $wDate->GetFormattedTimeString('Asia/Dubai', 'now', 'Q');      # Gulf Standard Time