차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
tech:php_친절한_날짜_표시 [2015/09/03 07:54] – 만듦 V_Ltech:php_친절한_날짜_표시 [2016/07/12 00:56] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 +{{tag>php 친절한 날짜 표시}}
 ====== Php 친절한 날짜 표시 ====== ====== Php 친절한 날짜 표시 ======
 +대충 인간적인 시간개념을 반환한다. [[tech:fuzzy|]]랄까?
 <file php> <file php>
-const int SECOND = 1; +<?php 
-const int MINUTE = 60 * SECOND; +
-const int HOUR = 60 * MINUTE; +
-const int DAY = 24 * HOUR; +
-const int MONTH = 30 * DAY;+
  
-var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks); +// PHP 5.3.0부터 작동 
-double delta = Math.Abs(ts.TotalSeconds);+// 츌쳐: http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time
  
-if (delta < 1 * MINUTE)+const SECOND = 1; 
 +const MINUTE = 60; 
 +const HOUR = 3600; 
 +const DAY = 86400; //24 * HOUR; 
 +const MONTH = 2592000; //30 * DAY; 
 + 
 +echo howold( mktime(10,1,4,3,23,2015)); 
 + 
 +function howold($oneday) { 
 +$delta = abs(time() - $oneday); 
 + 
 +if ($delta < 1 * MINUTE)
 { {
-  return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";+  return  "방금";
 } }
-if (delta < * MINUTE)+if ($delta < * MINUTE)
 { {
-  return "a minute ago";+  return "몇분전";
 } }
-if (delta < 45 * MINUTE)+if ($delta < 45 * MINUTE)
 { {
-  return ts.Minutes + minutes ago";+  return  "수십분 전";
 } }
-if (delta < 90 * MINUTE)+if ($delta < 90 * MINUTE)
 { {
-  return "an hour ago";+  return "한시간 전";
 } }
-if (delta < 24 * HOUR)+if ($delta < 24 * HOUR)
 { {
-  return ts.Hours + hours ago";+  return  "하루 전";
 } }
-if (delta < 48 * HOUR)+if ($delta < 48 * HOUR)
 { {
-  return "yesterday";+  return "어제쯤";
 } }
-if (delta < 30 * DAY)+if ($delta < 30 * DAY)
 { {
-  return ts.Days + days ago";+  return "힌달 이내";
 } }
-if (delta < 12 * MONTH)+if ($delta < 12 * MONTH)
 { {
-  int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30)); +  return "일년 이내";
-  return months <= 1 ? "one month ago" : months + " months ago";+
 } }
 else else
-{ +{  
-  int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365)); +  return "오래전"; 
-  return years <= 1 ? "one year ago" : years + " years ago";+}
 } }
 +?>
 </file> </file>
    
  
  
-{{tag>php 친절한 날짜 표시}}+