Header Ads

PHP 날짜,시간 함수


/*
checkdate
bool = checkdate(int month, int day, int year)
http://php.net/manual/en/function.checkdate.php
*/
$valid_date = checkdate(12,31,1999);
if($valid_date)
{
 echo "YES";
}
else
{
 echo "NO";
}

/*
time
int = time()
http://php.net/manual/en/function.time.php
*/
$nextWeek = time() + (7 * 24 * 60 * 60);
echo $nextWeek;

/* 
mktime
int = mktime(int hour, int minute, int second, int month, int day, int year, int is_dst)
http://php.net/manual/en/function.mktime.php
*/
$maketime = mktime();
echo $maketime;
$maketime = mktime(10,10,30,12,31,1999);
echo $maketime;

/*
date
string = date(string format, int timestamp)
http://php.net/manual/en/function.date.php
*/
$maketime = mktime(10,10,30,01,01,2000);
// Year
echo date("L", $maketime); // leap year 1 true, 0 false
echo date("Y", $maketime); // year 4 digits, 2000
echo date("y", $maketime); // year 2 digits, 00
// Month
echo date("F", $maketime); // month full text, January
echo date("M", $maketime); // month 3 letters, Jan
echo date("m", $maketime); // month 2 digits, 01
echo date("n", $maketime); // month 1 digits, 1
echo date("t", $maketime); // last day of month
// Day
echo date("d", $maketime); // day 2 digits, 01
echo date("j", $maketime); // day 1 digits, 1
echo date("l", $maketime); // day full text, Sunday
echo date("D", $maketime); // day 3 letters, Sun
echo date("w", $maketime); // day representation, 0~6
echo date("S", $maketime); // day 2 letters, nd
echo date("z", $maketime); // day of the year, 0~365
// Time
echo date("g", $maketime); // time 1 digits, 1~12
echo date("h", $maketime); // time 2 digits, 01~12
echo date("G", $maketime); // time 1 digits, 1~24
echo date("H", $maketime); // time 2 digits, 01~24
echo date("a", $maketime); // am, pm
echo date("A", $maketime); // AM, PM
echo date("i", $maketime); // minute 2 digits, 00~59
echo date("s", $maketime); // second 2 digits, 00~59
// Date
echo date("c", $maketime); // ISO 8601, 1999-12-31 T10:10:30+09:00
echo date("r", $maketime); // RFC 2822, Sat 10 Nov 2000 10:10:30+12:00
echo date("U", $maketime); // TimeStamp

/*
getdate
array = getdate(int timestamp)
http://php.net/manual/en/function.getdate.php
*/
$array_time = getdate(time());
foreach($array_time as $key=>$value)
{
 echo $key . ":" . $value . "
"; } echo $array_time["0"]; echo $array_time["month"]; echo $array_time["weekday"]; echo $array_time["yday"]; echo $array_time["year"]; echo $array_time["mon"]; echo $array_time["wday"]; echo $array_time["mday"]; echo $array_time["hours"]; echo $array_time["minutes"]; echo $array_time["seconds"]; /* microtime mixed = microtime(bool get_as_float) http://php.net/manual/en/function.microtime.php */ echo microtime(FALSE); echo microtime(TRUE);

No comments

Copyright 2016, minki. All rights reserved. Powered by Blogger.