Sep 042012
 

php에서 time() 을 호출하게 되면 unix timestamp를 반환하게 된다. 해당 값은 단위가 초이기 때문에 간단한 수칙연산으로 날짜를 변경이 가능하다.

하지만, 현재 시간에서 1달을 더하거나 할때에는 생각할 부분이 많다. 30 혹은 31일인 경우까지 고려를 해야 하며, 1년을 더 할 경우에는 윤년 계산까지 해야 한다.

이럴때 아래의 strtotime() 를 사용하면 보다 간편하게 계산이 가능하다.

 
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>

참고 URL: http://www.php.net/manual/en/function.strtotime.php
참고 URL: http://www.php.net/manual/en/function.time.php

Print Friendly

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 488

Warning: Invalid argument supplied for foreach() in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 490

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins