|
|
|
When developing a website with PHP it is often beneficial to report server times
and/or dates. On its own this ability is quite useful, but in combination
with further scripting, it allows you to account for time zones, datelines, etc,
thus improving the overall user experience. The popular forums software
Vbulletin, for example,
supports these functions natively. Best of all, you can output the
current server date/time with the following simple PHP instruction:
<? echo date("D M d, Y H:i:s"); ?> |
This will output: Fri Jan 03, 2003 12:01:21 (or the current date/time)
To change the formatting of the date/time, you only need to change the syntax in
the brackets to suit your new purpose. For example:
- A = Uppercase 12hr time syntax eg. PM
- a = Lowercase 12hr time syntax eg. pm
- D = Day eg. Fri
- d = Day eg. 03
- F = Full Text Month eg. January
- G = Hours in 24 hour format without leading zeros eg. 17
- g = Hours in 12 hour format without leading zeros eg. 7
- H = Hours in 24 hour format with leading zeros eg. 17
- h = Hours in 12 hour format with leading zeros eg. 07
- i = Minutes eg. 29
- M = Month eg. Jan
- m = Month eg. 01
- O = GMT time difference in hours eg. +0400
- S = Day of month suffix eg. st, nd, rd, or th.
- s = Seconds eg. 28
- T = Timezone setting eg. GMT, PST, EST, etc
- t = Total number of days in the month eg. 28, 31, etc.
- U = Seconds since the UNIX epoch eg. 1041604168
- W = Week number in year eg. 42 (42nd week in the year)
- w = numeric representation of the day eg. 1 = monday, 2 = tuesday,
etc.
- Y = Year eg. 2003
- y = Year eg. 03
- z = Day of the year eg. 002
A Few Examples To finish this tutorial there now follows a few
examples of standard date/time strings and the values they output. I hope
you enjoyed this tutorial and good luck with PHP! ;)
| Date String |
Example Output |
| date("F j, Y, g:i a"); |
- March 10, 2001, 5:16 pm |
| date("m.d.y"); |
- 03.10.01 |
| date("j, n, Y") |
- 10, 3, 2001 |
| date("D M j G:i:s T Y"); |
- Sat Mar 10 15:16:08 PST 2001 |
| date("H:i:s"); |
- 17:16:17 |
| date('\i\t \i\s \t\h\e jS \d\a\y.'); |
- It is the 10th day. * |
* = Don't forget to de-limit any normal letters you want to include with the
\ symbol, or else the date/time function will interpret the values as intended
date/time syntax.
- Tutorial written by Paul Dawson
| 
There are no comments for this tutorial yet. You can place a comment by clicking here.
|

|
|
 |
[WIP] Hairdresser Site Design Author: YinToniq Posted: Jul 03rd, 5:58am Activity: 1 replies, 42 views
|  | Simple Flash Help Needed (AS2) Author: stiney51 Posted: Jul 02nd, 2:40pm Activity: 9 replies, 57 views
|  | Transformers Author: Jacorre Posted: Jun 29th, 6:33pm Activity: 2 replies, 76 views
|  | Quick question about Jasc PaintShop Pro 9. Author: Rydium-41 Posted: Jun 28th, 8:21pm Activity: 2 replies, 76 views
|  | I bought film today!! Author: NikonErik Posted: Jun 27th, 12:04am Activity: 2 replies, 77 views
|  | New Battle Author: MoodsR4Cattle Posted: Jun 26th, 6:28pm Activity: 2 replies, 86 views
|  | Image Loading Author: funkyfela Posted: Jun 22nd, 9:00pm Activity: 1 replies, 85 views
|  | Headshot Critique Please Author: NikonErik Posted: Jun 19th, 11:32pm Activity: 6 replies, 155 views
|  | imagecopy() and imagecopyresized() problem Author: thatpyrokid Posted: Jun 18th, 3:05pm Activity: 1 replies, 151 views
|  | Problem With Regitration Code...? Author: RXS Posted: Jun 17th, 3:18am Activity: 2 replies, 153 views
|  | Topaz Labs do it again! Author: Tamlin Posted: Jun 17th, 12:08am Activity: 5 replies, 231 views
|  | [Photoshop] Anime Coloring Tutorial Author: Wavechan Posted: Jun 16th, 3:47pm Activity: 2 replies, 293 views
|  |
|
 |
 |
 |
 |
 |
| --- Site Resources --- |
| Total Tutorials: | 212 |
| Total Downloads: | 415 |
| Linkbase Links: | |
 |
|
 |
 |
|