메뉴 건너뛰기

프로그램언어

2017.04.13 18:27

PHP 날짜 함수

조회 수 17673 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
테스트 일 : 2011년 9월 7일

형식 : string date(string $format [, int $timestamp] )
  format parameters
    d => 01 to 31
    D => Mon through Sun
    w => 0(sunday) through 6(saturday)
    z => 0 through 365
    m => 01 through 12 (month)
    M => Jan through Dec
    t => 28 through 31 ( last day of month , 달 마지막 날 )
    Y => 1999 or 2011
    h => 01 through 12 (12 hour)
    H => 00 through 23 (24 hour)
    i => 00 to 59 (minutes)
    s => 00 through 59 (seconds)

오늘출력
echo date("Ymd");     출력->       20110907

오늘로 부터 3일 후
echo date("Y-m-d", strtotime("+3 day"));      출력->       2011-09-10

오늘로 부터 3일 전
echo date("Y-m-d", strtotime("-3 day"));      출력->       2011-09-04

오늘로 부터 일주일 전
echo date("Y-m-d", strtotime("-1 week"));      출력->       2011-08-31

유닉스 timestamp 값을 리턴
echo strtotime("now");      출력->      1315389514

특정일을 구하기
$oneweekbefore = strtotime("-1 week");
echo date("Y-m-d", strtotime("7 day", $oneweekbefore));      출력->       2011-09-07

특정일 구하기2-이번달 마지막날
mktime(시,분,초,월,일,년도)
echo date('t', mktime(0,0,0,9,7,2011);      출력->       30

이번주 월요일 구하기
$now1 = date("w");
$m = $now1-1;
echo date("Y-m-d", strtotime("-$m day"));


List of Articles
번호 제목 날짜 조회 수
340 $_FILES 2016.12.23 23847
339 $_SERVER 함수 2016.12.23 23943
338 $_SERVER 환경변수 2016.09.21 33237
337 $_SERVER변수 2014.02.27 24443
336 13자리 timestamp 생성하기 file 2020.09.28 649
335 addslashes — 문자열을 슬래시로 인용 2016.12.23 23083
334 addslashes 함수의 필요성 2015.04.14 24250
333 ajax refresh 시키기(자동리플래쉬) with php file 2017.03.06 23185
332 Ajax로 구연한 실시간 서버시간출력 file 2017.03.06 21031
331 AJAX로 해당 페이지에서 COOKIE 사용하기 2021.03.26 359
330 AJAX를 활용하여 JSON 댓글 처리하기 (PHP) 2018.07.04 8454
329 array (배열) 2015.04.14 24904
328 array_key_exists 배열에서 key가 존재하는지 확인 2016.12.23 22206
327 array_push 배열 끝에 하나 이상의 요소를 추가 2016.12.23 21604
326 array_slice 배열의 일부를 추출 2016.12.23 20775
325 base64 인코딩/디코딩 함수의 특징 file 2018.02.09 13078
324 call_user_func 사용자가 정의한 함수를 호출하여 실행고자 할 때 사용 2016.12.23 21302
323 class_exists 클래스가 정의되었는지 확인 2016.12.23 19881
322 Class를 이용한 DB Connection 소스 (Oracle, MyS 2014.02.27 30503
321 CodeIgniter - DB오류체크, 디버깅 여부 설정 2021.03.29 494
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved