본문 바로가기

PHP

(함수) date()

date()

 


// set the default timezone to use. Available since PHP 5.1 
date_default_timezone_set('UTC');   


// Prints something like: Monday 

echo date("l");   


// Prints something like: Monday 8th of August 2005 03:12:46 PM 

echo date('l jS \of F Y h:i:s A');   

// Prints: July 1, 2000 is on a Saturday 

echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));   /* use the constants in the format parameter */

// prints something like: Mon, 15 Aug 2005 15:12:46 UTC

echo date(DATE_RFC822);   

// prints something like: 2000-07-01T00:00:00+00:00 

echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000)); 

// prints something like: Wednesday the 15th

echo date('l \t\h\e jS');   
$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")); $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); 
$nextyear  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y")+1);   

//To find last sunday for given date: last sunday : 2012-09-30

$day = '2012-10-04';          
echo 'last sunday :  '.date("Y-m-d",strtotime($day." last Sunday "));