PHP date() examples
The code below are examples of using date function to get the current date with different formats.
<?php date_default_timezone_set("America/New_York"); echo date("Y-m-d")."<br/>"; echo date("Y.m.d") . "<br/>"; echo date("Y/m/d") . "<br/>"; echo date("YmdHis")."<br/>"; echo date("Y-m-d H:i:s")."<br/>"; echo date("Y-m-d H:i:s D, M d, Y")."<br/>"; echo date("Y-m-d",strtotime("2014-02-09 15:04:51"))."<br/>"; print_r(getdate()); echo "<br/>"; $mydate=getdate(date("U")); echo "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]"; echo "<br/>"; $tz = new DateTimeZone("America/New_York"); $dt = new DateTime("now", $tz); echo "America/New_York time>>>>>>>>".$dt->format('H:i:s D, M d, Y');
The output of the above code will print dates with the formats like the below:
2014-02-09 2014.02.09 2014/02/09 20140209163817 2014-02-09 16:38:17 2014-02-09 16:38:17 Sun, Feb 09, 2014 2014-02-09 Array ( [seconds] => 17 [minutes] => 38 [hours] => 16 [mday] => 9 [wday] => 0 [mon] => 2 [year] => 2014 [yday] => 39 [weekday] => Sunday [month] => February [0] => 1391981897 ) Sunday, February 9, 2014 America/New_York time>>>>>>>>00:02:07 Mon, Feb 10, 2014
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts