Date And Time Formatting With PHP

1057 0

$1*/ mo hosting! Get going with GoDaddy!


Hello again.In this tutorial I will explains about date and time Formatting . Date and and time is very important topic in Web Applications.
You may still ask yourself why I started with User Interface but take a look at this:
1202395558

Not many people can read this clearly without any problems. This is the current server time. Now see this:
2008-02-07 16:45:58
Feb 07 08 4:45:58 pm

Let’s see some examples :

Date format characters’ legend by examples:

d – Represent a day, from 01 to 31.
m – Represent a month, from 01 to 12.
y – Represent a Year , two digits.

D – Textual representation of a day,  Mon through Sun.
j – Numeric representation of a day, without leading zeros 1 through 31.
n – Numeric representation of a month, without leading zeros 1 through 12.
Y – Numeric representation of a year, four digits.

S – English ordinal suffix for the day of the month. Consist of 2 characters st, nd, rd or th.
F – Textual representation of a month, January through December.

M – Textual representation of a month, three letters Jan through Dec.

Time Formatting

G  24-hour format of an hour without leading zeros 0 through 23.
i  Numeric representation of minutes with leading zeros 00 through 59.
s  Numeric representation of seconds with leading zeros 00 through 59.
H  24-hour format of an hour with leading zeros 00 through 23.
a  Lowercase Ante meridiem and Post meridiem am or pm.
g  12-hour format of an hour without leading zeros 1 through 12.
A  Uppercase Ante meridiem and Post meridiem AM or PM.
h 12-hour format of an hour with leading zeros 01 through 12.
And when we combine both date and time formatting we get some really nice looking output strings.

Comments

comments

In this article

Join the Conversation