CancelImage Upload

How to convert a PHP timestamp into a human readable format

Timestamps are great for the following reason. They can be converted into any chosen format without having to do much pre-converting. This saves a lot of time compared to times and dates stored in human readable formats.

How then do you convert a timestamp into something human readable? In PHP the function for this job is strftime:

strftime(format, timestamp);

To establish the format we can use alphanumeric values that are then translated into the appropriate data. Here is an example converting the unix code 1238706731 into 02 Apr 2009:

echo strftime("%d %b %Y", 1238706731);

Here is a list of format codes:

Shortcut for weekdays (Mon, Tue, Wed)%a
Full name of weekdays (Monday, Tuesday)%A
Shortcut of the month (Jan, Feb, Mar)%b
Month Written out (January, February)%B
Day of the month with leading Zero%d
24 Hour format with leading Zero%H
12 Hour format with leading Zero%I
Day of the year 001-366%j
Month without leading Zero%m
Minutes as number (0-59)%M
AM or PM%p
Seconds as numbers (0-59)%S
Week number starting first Sunday%U
Week number starting first Monday%W
Numeric representation of the day of the week%w
Two digit year representation (99)%y
Four digit year representation (1999)%Y
Difference to a time zone%Z


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com