Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try to use this class: I defined some constans to translate to spanish but you can ignore those or make the validation language for the others functions!! </p> <p>You can focus on the functions: <strong>shortDateHuman(), longDateHuman(), shortTimeHuman(), longTimeHuman()</strong></p> <p>In order to use it you can do: <code>$datetest=new Date($language);</code> and then use</p> <p><code>$datetest-&gt;longDateHuman();</code></p> <p>In addition, you can check the function <strong>setGMTOffset</strong> if you need it.</p> <pre><code>class Date { var $gmtoffset; var $year; var $month; var $day; var $hour; var $minute; var $second; var $idioma; function Date($lang) { //setlocale (LC_TIME,en_US); list($this-&gt;year, $this-&gt;month, $this-&gt;day) = split("-", gmdate("Y-m-d")); list($this-&gt;hour, $this-&gt;minute, $this-&gt;second) = split(":", gmdate("g:i:s")); $this-&gt;gmtoffset = 0; $this-&gt;idioma=$lang; } function getYear() { return $this-&gt;year; } function setYear($year) { $year = intval($year); if($year &gt;= 0) { $this-&gt;year = $year; } else { //throw new Exception("Invalid year! Prior to 0 A.D.!"); } return true; } function getMonth() { return $this-&gt;month; } function setMonth($month) { $month = intval($month); if(($month &gt;= 1) &amp;&amp; ($month &lt;= 12)) { $this-&gt;month = $month; } else { //throw new Exception("Invalid month! Not between 1 and 12!"); } return true; } function getDay() { return $this-&gt;day; } function setDay($day) { $day = intval($day); if(($day &gt;= 1) &amp;&amp; ($day &lt;= 31)) { $this-&gt;day = $day; } else { //throw new Exception("Invalid day! Not between 1 and 31!"); } return true; } function getHour() { return $this-&gt;hour; } function setHour($hour) { $hour = intval($hour); if(($hour &gt;= 0) &amp;&amp; ($hour &lt;= 23)) { $this-&gt;hour = $hour; } else { //throw new Exception("Invalid hour! Not between 0 &amp; 23!"); } return true; } function getMinute() { return $this-&gt;minute; } function setMinute($minute) { $minute = intval($minute); if(($minute &gt;= 0) &amp;&amp; ($minute &lt;= 59)) { $this-&gt;minute = $minute; } else { //throw new Exception("Invalid minute! Not between 0 and 59!"); } return true; } function getSecond() { return $this-&gt;second; } function setSecond($second) { $second = intval($second); if(($second &gt;= 0) &amp;&amp; ($second &lt;= 59)) { $this-&gt;second = $second; } else { //throw new Exception("Invalid second! Not between 0 and 59!"); } return true; } function getGMTOffset() { return $this-&gt;gmtoffset; } function setGMTOffset($gmtoffset) { $gmtoffset = intval($gmtoffset); if(($gmtoffset &gt;= -12) &amp;&amp; ($gmtoffset &lt;= 12)) { $this-&gt;gmtoffset = $gmtoffset; } else { //throw new Exception("Invalid GMT offset! Not between -12 and 12!"); } return true; } function setDate($year, $month, $day) { $this-&gt;setYear($year); $this-&gt;setMonth($month); $this-&gt;setDay($day); return true; } function setTime($hour, $minute, $second, $gmtoffset = 0) { $this-&gt;setHour($hour); $this-&gt;setMinute($minute); $this-&gt;setSecond($second); $this-&gt;setGMTOffset($gmtoffset); return true; } function setDateTime($year, $month, $day, $hour, $minute, $second, $gmtoffset) { $this-&gt;setDate($year, $month, $day); $this-&gt;setTime($hour, $minute, $second, $gmtoffset); return true; } function timestamp() { # This function returns a user's correct timezone in the form # of a unix timestamp. return mktime($this-&gt;hour + $this-&gt;gmtoffset, $this-&gt;minute, $this-&gt;second, $this-&gt;month, $this-&gt;day, $this-&gt;year); } function longDateTimeHuman() { # Returns a date string like "Saturday, November 5, 2005 3:25 PM". return date("l, j F, Y g:i A", $this-&gt;timestamp()); } function diaSemana(){ # Returns a day string like "Saturday". return date("l", $this-&gt;timestamp()); } function mes(){ # retorna un string del mes "November". return date("F", $this-&gt;timestamp()); } function diaSemana_es($diaen){ switch($diaen) { case "Saturday": return("Sábado");break; case "Sunday": return("Domingo");break; case "Monday": return("Lunes");break; case "Tuesday": return("Martes");break; case "Wednesday": return("Miércoles");break; case "Thursday": return("Jueves");break; case "Friday": return("Viernes");break; } } function mes_es($mesen){ switch($mesen) { case "January": return(_JAN);break; case "February": return(_FEB);break; case "March": return(_MAR);break; case "April": return(_APR);break; case "May": return(_MAY);break; case "June": return(_JUN);break; case "July": return(_JUL);break; case "August": return(_AUG);break; case "September": return(_SEP);break; case "October": return(_OCT);break; case "November": return(_NOV);break; case "December": return(_DEC);break; } } function longDateHuman() { # Returns a date string like "Saturday, November 5, 2005". if($this-&gt;idioma=="en") return date("l, j F , Y", $this-&gt;timestamp()); else { return "".$this-&gt;diaSemana_es($this-&gt;diaSemana()).", ".$this-&gt;mes_es($this-&gt;mes())." ".$this-&gt;day.", ".$this-&gt;year; } } function shortDateHuman() { # Returns a date string like "November 5, 2005". return date("F j, Y", $this-&gt;timestamp()); } function longTimeHuman() { # Returns a time like "3:32:56 PM". F j of Y, g:i a return date("g:i:s A", $this-&gt;timestamp()); // return date("F j of Y", $this-&gt;timestamp()); } function shortTimeHuman() { # Returns a time like "3:32 PM". return date("g:i A", $this-&gt;timestamp()); } function militaryTime() { # Returns a time like "15:34:24". return date("h:i:s", $this-&gt;timestamp()); } function SQLDate() { return date("Y-m-d", $this-&gt;timestamp()); } function SQLDate_convertir($timestamp){ // echo date("Y-m-d", $timestamp); // echo $timestamp; // $aux=getdate($timestamp); // $aux=mktime($timestamp); // $aux=gmstrftime($timestamp); //echo // print_r(getdate($timestamp)); // $aux=$timestamp; //$aux=date("Y-m-d", $timestamp); $aux=split(" ",$timestamp); //print_r($aux); return $aux[0]; } function SQLTime() { return date("h:i:s", $this-&gt;timestamp()); } function SQLDateTime() { return date("Y-m-d h:i:s", $this-&gt;timestamp()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload