PHP 날짜 시간 더하기 빼기 함수 strtotime date time > 개발

본문 바로가기
사이트 내 전체검색

개발

PHP 날짜 시간 더하기 빼기 함수 strtotime date time

페이지 정보

profile_image
작성자 관리자 (114.♡.85.207)
댓글 0건 조회 10,793회 작성일 16-04-11 22:23

본문

strtotime

(PHP 4, PHP 5, PHP 7)
strtotime — Parse about any English textual datetime description into a Unix timestamp

설명 ¶

int strtotime ( string $time [, int $now = time() ] )



Example
[code]
<?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";
?>
[/code]

[code]
<?php
//아래 함수들의 output 은 timestamp 형태의 숫자이다.
echo time();
echo strtotime("now");
echo strtotime("+1 hour");

// 아래 함수의 output 은 사람이 보기 쉬운 string 형태이다.
echo date( 'Y-m-d H:i:s', time() );  // YYYY-mm-dd HH:ii:ss
?>
[/code]

[code]
<?php
// 특정 날짜를 기준으로 날짜 더하고 빼기
$prev_date = date("Y-m-d", strtotime(date("Y-m-d") . " -1 days")); // 하루전 날자
$next_date = date("Y-m-d", strtotime(date("Y-m-d") . " +1 days")); // 하루후 날자
// 위 date("Y-m-d") 자리에 "2010-10-10" 이런식으로 넣어도 된다.

$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -3 month")); // 3달전
$start_date = date("Y-m-d", strtotime(date("Y-m-d") . " -7 year")); // 7년전
?>
[/code]

그러니까, strtotime 과 date 함수만 잘 활용하면, 다 해 먹을 수 있다.  ^^

추천0

댓글목록

등록된 댓글이 없습니다.

Total 387건 3 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
3475180012-20
3465047011-27
3455044003-09
3445038001-03
3434998006-04
3424982007-04
3414943001-11
3404941004-24
3394917004-09
3384889001-31
3374882005-13
3364869005-29
3354811005-07
3344783007-29
3334777010-10
3324774007-22
3314771011-11
3304761004-25
3294741005-19
3284725010-02

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.