[ php ] 날짜 시간 함수 정리 ( 어제, 내일, 일주일전, 한달전, 다음달, 다음주 등등 ) > php

본문 바로가기

사이트 내 전체검색

php

[ php ] 날짜 시간 함수 정리 ( 어제, 내일, 일주일전, 한달전, 다음달, 다음주 등등 )

작성일 18-09-27 15:33

페이지 정보

작성자 웹지기 조회 23,886회 댓글 0건

본문

[code]

<?php 

$toDay = date('Ymd'); //오늘

$yesterDay = $toDay -1; // 어제



date("Y-m-d H:i:s"); //24시간으로 출력

date("Y-m-d h:i:s"); // 12시간으로 출력

date("Ymd"); //날짜까지만 출력

date("h:i:s"); // 시간만 출력


date("Y-m-d H:i:s",time()); //timestamp 형식으로 날짜/ 시간의 형태로 출력


date("Y-m-d",strtotime ("+1500 minutes")); // 1500분을 추가한 형태

date("Y-m-d H:i:s", strtotime("-1 day")); // 어제

date("Y-m-d H:i:s", strtotime("now")); // 현재

date("Y-m-d H:i:s", strtotime("+1 day")); // 내일

date("Y-m-d H:i:s", strtotime("-1 week")); // 일주일 전

date("Y-m-d H:i:s", strtotime("+1 week")); // 일주일 후

date("Y-m-d H:i:s", strtotime("-1 month")); // 한달 전

date("Y-m-d H:i:s", strtotime("+1 month")); // 다음달

date("Y-m-d H:i:s", strtotime("+1 week 2 days 3 hours 4 seconds")); // 1주 2일 3시간 4초 후

date("Y-m-d H:i:s", strtotime("next Thursday")); // 다음주 목요일

date("Y-m-d H:i:s", strtotime("last Monday")); // 지난 월요일

date("Y-m-d H:i:s", strtotime("19 December 2016")); // 2016년 12월 19일


//날짜 입력시 사용가능 특수문자는 -와 없는 형태 두가지만 가능

date("Ymd",strtotime ("-1 days", strtotime('20070819'))); //특정날짜에서 하루 빼기

date("Ymd",strtotime ("+1 days", strtotime('2007-08-19')));//특정날짜에서 하루 빼기


date( "Y-m-d\TH:i:s", strtotime('20070101040404') ); //timestamp의 형태 정상적으로 처리안됨 

date( "Y-m-d\TH:i:s", strtotime('2007-01-01 04:04:04') ); //정상적으로 처리됨(제너센스 rss에서 사용) 


//문자형 날짜와 문자형 날짜 사이의 일수 구하기

// 문자형 날짜를 초로 계산하여 뺀다음에 일자로 변환해줌( 가장 정확함) 

echo (strtotime('20070803') - strtotime('20070801'))/60/60/24;


//오늘 날짜부터 지정한 일수(day)후의 날짜로 timestamp형식으로 출력하기 

function plus_day($day) { 

    return mktime(0,0,0,date("m"),date("d")+$day,date("Y")); 

}


//한줄로 오늘 날짜 시간 뽑아오기 

list($y,$m,$d,$h,$i,$s) = explode(" ",date("Y m d h i s"));

[/code]


추천0

비추천 0

댓글목록

등록된 댓글이 없습니다.

전체 82건 4 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기