본문 바로가기

개인 공부

[php] 기본적인 함수 사용_2 (timestamp,strotitome,date)

728x90

date함수.. 정말 많이 사용하게 된다.. 달력 예약 시스템은 걍 되는거 아니냐 이런느낌..?

걍 되지 되는데 ... 기능이 다 다르잖아 ....

/* date 날짜 함수 */
/* date(format, timestamp) date('필수,옵션) */
asd(date('Y-m-d H:i:s'));  // 현재시간 표시 2022-11-16 16:13:42;
asd(date('Y-m-d', '2022-10-10'));  /* timestamp값이 아니라 에러 발생 1970-01-01 표시 */

기보함수는 현재시각이 timestamp값으로 안넣으면 에러가 발생해 1970년대로 회귀해버린다. 그 시대에 살고싶지 않다면 timestamp값을 사용해야한다는걸 반드시 숙지해야함.

/* mktime -> 시간과 날짜를 timestamp로 변환시켜준다.*/
/* mktime(hour, minute, second, month, day, year )*/
$timestamp = mktime(3,30,30,2,20,2018);
asd(date('Y-m-d H:i;s',$timestamp) .  ' mktime');

/* strtotime() */
$timestamp = strtotime('Now');
asd(date('Y-m-d H:i;s',$timestamp) .  ' Now');
$timestamp = strtotime('+30 seconds');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +30 seconds');
$timestamp = strtotime('+30 minutes');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +30 minutes');
$timestamp = strtotime('+30 hours');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +30 hours');
$timestamp = strtotime('+1 month');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +1 month');
$timestamp = strtotime('+1 year');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +1 year');
$timestamp = strtotime('+10 days');
asd(date('Y-m-d H:i;s',$timestamp) .  ' +10 days');

/* 보통 사용은 현재값을 가져와 더하는 용도로 사용한다. */
$timestamp = strtotime('+20 days',strtotime(date('Y-m-d'))); /* 2022-12-06 +20일 */
asd(date('Y-m-d',$timestamp));

mktime이라는 함수가 있긴한데.. 변환시키는게 너무 까다로워서 잘 사용하지 않게됨...
strtotime함수가 진짜 개꿀임 걍 두번적어버려도됨 ..
날짜는 많이 설명할게 없네 보고 이해해놓고 필요할때마다 찾아서 쓰면되는부분이라 ..

 

일이 너무 바쁘고.. 바쁘니까 너무 피곤해서 잘 못만들고 있음 ... 시간을 내서 해야하는건데

너무 힘들다.. 나약하지 않도록 노력해야지 ..

728x90
댓글