Desde 1994 en la Red. La pagina de los aficionados a la electronica, informatica y otras curiosidades de la vida. No dudes en visitarnos.
Ahora 2 visitas.| 3408569 Visitas (desde Dic. 2011), hoy: 280 Visitas 698 Pag. Vistas , ultimos 36 dias: 10109 Visitas. 43984 Pag. Vistas. Tu IP: 3.135.209.249
Que ando curioseando:
AutosuficienciaCosas de casaElectronicaEn InternetInformáticaMundo MisticoSin categoríaSociedadTe lo recomiendo

Gestion de Fecha y Dia en PHP

Time and Date 
These NetCloak commands refer to the current time and date. 
PHP code has be written to mimic the behavior. 
<INSERT_TIME> 
<SHOW_TIME> 
<HIDE_TIME> 
 
<INSERT_DATE> 
<SHOW_DATE> 
<HIDE_DATE> 
 
<INSERT_COUNTDOWN> 
 
<INSERT_DAY> 
<SHOW_DAY> 
<HIDE_DAY>
--------------------------------------------------------------------------------
<INSERT_TIME offset format> 
The time, one timezone east, is <?php InsertTime(+1,"SHORT"); ?>.
InsertTime( offset, format ) 
<?php 
    //----------------------------------------------------- 
    // InsertTime() 
    // - - - - - - 
    // Prints the current time. 
    // 
    // $offset - Hours difference between the displayed 
    //           time and the web server's time. 
    // $format - "SHORT" or "LONG". 
    //----------------------------------------------------- 
    function InsertTime($offset=0, $format="long") 
    { 
        $kHour = 60*60; 
      Š        if( strcasecmp($format,"long") == 0 ) 
            print date("g:i:s A",time()+$offset*$kHour); 
        else 
            print date("g:i A",time()+$offset*$kHour); 
    } 
?>
--------------------------------------------------------------------------------
<SHOW_TIME time1 time2 ...> 
<?php if( ShowTime("15:0 15:1 15:2") ) { ?>
  This text is displayed from 3:00:00 pm to 3:29:59 pm.
<?php } ?>
ShowTime( times ) 
<?php 
    //----------------------------------------------------- 
    // ShowTime($times) 
    // - - - - - - - - 
    // This function will return true if the current time 
    // is specifed in the parameters. 
    // 
    // $times - a string in the format "time1 time2 ..." 
    //          where time# is in the format "H[:i[:s]]" 
    // 
    // Example: ShowTime("08:3") returns true if the time 
    //                          is 8:30:00 am - 8:39:59 am 
    //----------------------------------------------------- 
    function ShowTime( $times ) 
    { 
        if( !is_array($times) ) 
          $times = explode(" ",trim($times)); 
    Š        while( $time = each($times) ) 
        { 
            $t = trim($time[value]); 
            if( strlen($t) == 1 ) 
             $t = "0".$t; 
            if( strlen($t) > 0 ) 
              if( strcmp($t,substr(date("G:i:s"),0,strlen($t))) == 0 || 
                  strcmp($t,substr(date("H:i:s"),0,strlen($t))) == 0 ) 
                return true; 
        } 
  Š        return false; 
    } 
?>
--------------------------------------------------------------------------------
<HIDE_TIME time1 time2 ...> 
<?php if( HideTime("11") ) { ?>
  This text is hidden from 11:00:00 am to 11:59:59 am.
<?php } ?>
HideTime( times ) 
<?php 
    //----------------------------------------------------- 
    // HideTime($times) 
    // - - - - - - - - 
    // Returns false if the current time is specified in 
    //         the parameters. 
    // 
    // See: ShowTime(). 
    //----------------------------------------------------- 
    function HideTime( $times ) { 
     return !ShowTime($times); 
    } 
?>
--------------------------------------------------------------------------------
<INSERT_DATE offset format> 
The date, three timezones west, is <?php InsertDate(-3,"LONG"); ?>.
InsertDate( offset, format ) 
<?php 
    //----------------------------------------------------- 
    // InsertDate() 
    // - - - - - - 
    // Prints the current date. 
    // 
    // $offset - Hours difference between the displayed 
    //           date and the web server's date. 
    // $format - "SHORT" or "LONG". 
    //----------------------------------------------------- 
    function InsertDate($offset=0, $format="long") 
    { 
        $kHour = 60*60; 
      Š        if( strcasecmp($format,"long") == 0 ) 
            print date("l, F j, Y",time()+$offset*$kHour); 
        else 
            print date("m/d/y",time()+$offset*$kHour); 
    } 
?>
--------------------------------------------------------------------------------
<SHOW_DATE begin end> 
<?php if( ShowDate("8/7/00@11:41","8/12/00") ) { ?>
  This text is displayed after 7 Aug 2000 @ 11:41 but before 12 Aug 2000.
<?php } ?>
ShowDate( begin, end ) 
<?php 
    //----------------------------------------------------- 
    // ShowDate($begin,$end) 
    // - - - - - - - - 
    // Returns true if the current date and time is after 
    //   or including $begin and before $end. 
    // 
    // Both $begin and $end should be formatted as: 
    //   "m/d/y[@H[:i[:s]]]" 
    // 
    // If $begin equals 0 or "*", the function returns true 
    //   if the current date is before $end. 
    // 
    // If $end equals 0 or "*", the function returns true 
    //   if the current date is after $begin. 
    //        Š    // 
    // Example: ShowDate("1/1/00","1/1/01") returns true 
    //   during the year 2000. 
    //----------------------------------------------------- 
    function ShowDate( $begin, $end = 0 ) 
    { 
        if( $end == 0 ) 
        { 
            $list = explode(" ",trim($begin)); 
            $begin = $list[0]; 
            $end = $list[sizeof($list)-1]; 
 Š            if( $end == "" ) 
                $end = 0; 
        } 
Š        $list = array( "begin", "end" ); 
Š        while( list($key,$value) = each($list) ) 
        { 
            if( is_string( $$value ) && strcmp($$value,"*") != 0 ) 
            { 
                list($date,$time) = explode("@",$$value); 
                list($month,$day,$year) = explode("/",$date); 
                list($hour,$min,$sec) = explode(":",$time); 
Š                $$value = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year); 
            } 
            else if( is_string( $$value ) && strcmp($$value,"*") == 0 ) 
            $$value = 0; 
        } 
Š        return( $begin <= time() && ($end == 0 || time() < $end) ); 
    } 
?>
--------------------------------------------------------------------------------
<HIDE_DATE begin end> 
<?php if( HideDate("8/1/00","8/7/00") ) { ?>
  This text is hidden between 1 Aug 2000 and 7 Aug 2000.
<?php } ?>
HideDate( begin, end ) 
<?php 
    //----------------------------------------------------- 
    // HideDate($begin,$end) 
    // - - - - - - - - 
    // Returns false if the $begin <= current date < $end. 
    // 
    // See: ShowDate(). 
    //----------------------------------------------------- 
    function HideDate( $begin, $end ) 
    { 
        return !ShowDate($begin,$end); 
    } 
?> 
--------------------------------------------------------------------------------
<INSERT_COUNTDOWN_WDHM date@time "Weeks" "Days" "Hours" "Minutes"> 
The New Year is in <?php InsertCountdown("1/1/".(date("Y")+1)); ?>.
InsertCountdown( Date@Time ) 
<?php 
    //----------------------------------------------------- 
    // InsertCountdown($dateTime) 
    // - - - - - - - - 
    // Prints the number of weeks, days, hours, and minutes 
    // between the current time() and $dateTime. 
    // 
    // $dateTime should be formatted as: 
    //   "m/d/y[@H[:i[:s]]]" 
    // 
    // Example: Countdown to Halloween Festivities! 
    //          InsertCountdown("10/31/2000@19:30") 
    //----------------------------------------------------- 
    function InsertCountdown( $dateTime, $sWeek = "Week", 
                                         $sDay = "Day", 
                                         $sHour = "Hour", 
                                         $sMin = "Minute", 
                                         $sSec = "" ) 
    { 
        print Countdown( $dateTime, $sWeek, $sDay, $sHour, $sMin, $sSec ); 
    }
Countdown( Date@Time ) 
    //----------------------------------------------------- 
    // Countdown($dateTime) 
    // - - - - - - - - 
    // Returns a string representing the difference between 
    // the current time and the input time. 
    // 
    // $dateTime should be formatted as: 
    //   "m/d/y[@H[:i[:s]]]" 
    // 
    // Example: Countdown to Halloween Festivities! 
    //       InsertCountdown("10/31/2000@19:30") 
    //----------------------------------------------------- 
    function Countdown( $dateTime, $sWeek = "Week", 
                                   $sDay = "Day", 
                                   $sHour = "Hour", 
                                   $sMin = "Minute", 
                                   $sSec = "" ) 
    { 
        $kSec = 1; 
        $kMin = 60*$kSec; 
        $kHour = 60*$kMin; 
        $kDay = 24*$kHour; 
        $kWeek = 7*$kDay; 
    Š        list($date,$time) = explode("@",$dateTime); 
        list($month,$day,$year) = explode("/",$date); 
        list($hour,$min,$sec) = explode(":",$time); 
      Š        $inTime = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year); 
  Š        $time_difference = abs(time()-$inTime); 
      Š        $weeks = ( empty($sWeek) ? 0 : floor($time_difference / $kWeek) ); $time_difference -= $weeks * $kWeek; 
        $days  = ( empty($sDay)  ? 0 : floor($time_difference / $kDay)  ); $time_difference -= $days * $kDay; 
        $hours = ( empty($sHour) ? 0 : floor($time_difference / $kHour) ); $time_difference -= $hours * $kHour; 
        $mins  = ( empty($sMin)  ? 0 : floor($time_difference / $kMin)  ); $time_difference -= $mins * $kMin; 
        $secs  = ( empty($sSec)  ? 0 : floor($time_difference / $kSec)  ); 
 Š        $out  = ( $weeks == 0 ? "" :                         "$weeks $sWeek" . ($weeks>1?"s":"") ); 
        $out .= ( $days  == 0 ? "" : (empty($out)?"":", ") . "$days $sDay"   . ( $days>1?"s":"") ); 
        $out .= ( $hours == 0 ? "" : (empty($out)?"":", ") . "$hours $sHour" . ($hours>1?"s":"") ); 
        $out .= ( $mins  == 0 ? "" : (empty($out)?"":", ") . "$mins $sMin"   . ( $mins>1?"s":"") ); 
        $out .= ( $secs  == 0 ? "" : (empty($out)?"":", ") . "$secs $sSec"   . ( $secs>1?"s":"") ); 
  Š        print $out; 
    } 
?>
In Action 
The New Year is in 41 Weeks, 1 Day, 20 Hours, 29 Minutes. 
--------------------------------------------------------------------------------
<INSERT_DAY offset> 
Today is <?php InsertDay(); ?>
InsertDay( offset, format ) 
<?php 
    //----------------------------------------------------- 
    // InsertDay() 
    // - - - - - - 
    // Prints the day of the week. 
    // 
    // $offset - Hours difference between the displayed 
    //           day and the web server's day. 
    // $format - "SHORT" or "LONG". 
    //----------------------------------------------------- 
    function InsertDay($offset=0, $format="long") 
    { 
        $kHour = 60*60; 
      Š        if( strcasecmp($format,"long") == 0 ) 
         print date("l",time()+$offset*$kHour); 
        else 
         print date("D",time()+$offset*$kHour); 
    } 
?>
 
--------------------------------------------------------------------------------
<SHOW_DAY day1 day2 ...> 
<?php if( ShowDay("FRI MON") ) { ?>
  This text is displayed on Friday and Monday.
<?php } ?>
ShowDay( days ) 
<?php 
    //----------------------------------------------------- 
    // ShowDay($days) 
    // - - - - - - - - 
    // Returns true if today is in the list of days. 
    // 
    // $days should be formatted: 
    //   "day1 day2 day3 ..." 
    // 
    // i.e.: 
    //   "MON TUE WED" 
    //----------------------------------------------------- 
    function ShowDay( $days ) 
    { 
        if( !is_array($days) ) 
            $days = explode(" ",$days); 
   Š        while( $day = each($days) ) 
        { 
            $d = trim($day[value]); 
            if( strlen($d) > 0 && stristr(date("l"),$d) ) 
                return true; 
        } 
        return false; 
    } 
?>
--------------------------------------------------------------------------------
<HIDE_DAY day1 day2 ...> 
<?php if( HideDay("TUE THU") ) { ?>
  This text is hidden on Tuesday and Thursday.
<?php } ?>
HideDay( days )

<?php
    //—————————————————–
    // HideDay($days)
    // – - – - – - – -
    // Returns false if today is in the list of days.
    //
    // $day should be formatted:
    //   “day1 day2 day3 …”
    //
    // i.e.:
    //   “MON TUE WED”
    //—————————————————–
    function HideDay( $days )
    {
        return !ShowDay($days);
    }
?>

********************************** ************

otro
A ver… lo mas aconsejable en este caso seria ocupar un poco de javascrip. La idea es que al correr cada segundo, sea el cliente (y no el servidor) el que ejecute la accion de actualizar.

Entonces, lo primero sera crear una instancia del objeto Date() en js, para extraer de ahi los valores en horas, minutos y segundos para actualizar nuestro reloj por cada segundo haciendo una recursion en la funcion con un intervalo de tiempo. Pero antes, es necesario tener claro donde vamos a poner los valores del reloj. Para esto vamos a crear un tag ‘div’ donde va a estar situado el reloj y asignandole un id unico (o un nombre), el que en este caso sera “contenedor_reloj”. Esto se hace asi:

<div id=”contenedor_reloj”></div>

Entonces ya tenemos el contenedor, vamos por la funcion que muestra el reloj en el formulario

Veamos la funcion:
____________________________________

<script language=”JavaScript”>
function HoraActual()
{
var esteMomento = new Date()
var hora = esteMomento.getHours()
var minuto = esteMomento.getMinutes()
var segundo = esteMomento.getSeconds()
HoraCompleta= hora + ” : ” + minuto + ” : ” + segundo;
document.getElementById(“contenedor_reloj”).innerHTML= HoraCompleta;
setTimeout(“HoraActual()”,1000)
}
</script>
________________________

Ok, tenemos la funcion que se actualiza por intervalos de 1000 milisegundos (en la linea de setTimeout) llamandose a si misma. Ahora solo queda llamar a esta funcion al inicio en el tag body:

<body onload=”HoraActual()”>

Esto seria. Ojala te sirva y si es asi, no olvides cerrar y puntuar la pregunta

Saludos

KoP. 

Re: hora actualizada  07/11/2007 
07/11/2007
 
Experto  Acabo de revisar la funcion y me di cuenta que esteticamente no se ve bien cuando alguno de los componentes (hora, minuto o segundo) es menor que 10, es decir, por ejemplo cuando es medianoche con 7 minutos y 3 segundos se muestra como

0 : 7 : 3

Esto ocurre cuando escribes codigo estando seguro que es correcto, pero sin probarlo para todos los casos. Me corrijo entonces y pongo el codigo de la funcion js corregido (y bien probado).
_________

function HoraActual(){
var esteMomento = new Date();
var hora = esteMomento.getHours();
if(hora < 10) hora = ’0′ + hora;
var minuto = esteMomento.getMinutes();
if(minuto < 10) minuto = ’0′ + minuto;
var segundo = esteMomento.getSeconds();
if(segundo < 10) segundo = ’0′ + segundo;
HoraCompleta= hora + ” : ” + minuto + ” : ” + segundo;
document.getElementById(‘div_reloj’).innerHTML = HoraCompleta;
setTimeout(“HoraActual()”,1000)
}

Saludos!

KoP 

RE: hora actualizada  07/11/2007 
07/11/2007
 
Usuario  Hola!! ok KoP entiendo perfectamente lo q me quieres decir y me sirve pero tengo otro problemita q es el siguiente: yo quiero colocar la hora en una tabla el copie tu codigo a esa tabla y me quedo asi el codigo

<table align=”right” border=”0″ >
<tr>
<th>
<div id=”contenedor_reloj”></div>
<script language=”JavaScript”>
function HoraActual(){
var esteMomento = new Date();
var hora = esteMomento.getHours();
if(hora < 10) hora = ’0′ + hora;
var minuto = esteMomento.getMinutes();
if(minuto < 10) minuto = ’0′ + minuto;
var segundo = esteMomento.getSeconds();
if(segundo < 10) segundo = ’0′ + segundo;
HoraCompleta= hora + ” : ” + minuto + ” : ” + segundo;
document.getElementById(‘div_reloj’).innerHTML = HoraCompleta;
setTimeout(“HoraActual()”,1000)
}
</script>
<body onload=”HoraActual()”> </body>
</th>
</tr>
</table>

pero no me muestra nada entonces no se q pasa alli. x favor cuando tengas tiempo resp y gracias x tu ayuda. 

Re: hora actualizada  07/11/2007 
07/11/2007
 
Experto  Tienes un error de concepto en los tags HTML.

Estimado, un documento HTML tiene, (digamos) 2 partes: una (y solo una) cabecera (un <head></head>) y un (y solo un) cuerpo (<body></body>). El primero es el que carga la informacion de la pagina, como el titulo (que aparece en la parte superior de la ventana del navegador), el autor, la validez, las palabras para busqueda, etc, etc. Esta data no se muestra en pantalla, sino que es informativa.
El segundo es el que muestra el contenido de la pagina, ahi pones tus tablas, tus encabezados de pagina, etc, etc.

Importantisimo: Un documento html NO PUEDE LLEVAR MAS DE UN TAG <body>, es decir, el parametro onload() que lleva la funcion que te envie va puesto en el body que ya tiene tu pagina.

Como segunda observacion, siempre es recomendable no escribir scripts js a mitad de una tabla. Si bien puede que funcione, no se ve bien y te desordena el codigo para futuras modificaciones.

Ok, ya aclarado eso, lo que debes hacer es:
1 – Borra ese <body onload…> que pusiste en la tabla.

2 – En el documento que ya tienes, busca el tag <body> (que esta al principio de la pagina) y reemplazalo por <body onload=”HoraActual()”> .

3 – Bajo ese <body onload…> pon el javascript que te envie:

<script language=”JavaScript”>
function HoraActual(){
var esteMomento = new Date();
var hora = esteMomento.getHours();
if(hora < 10) hora = ’0′ + hora;
var minuto = esteMomento.getMinutes();
if(minuto < 10) minuto = ’0′ + minuto;
var segundo = esteMomento.getSeconds();
if(segundo < 10) segundo = ’0′ + segundo;
HoraCompleta= hora + ” : ” + minuto + ” : ” + segundo;
document.getElementById(‘div_reloj’).innerHTML = HoraCompleta;
setTimeout(“HoraActual()”,1000)
}
</script>

4 – La tabla quedaria asi:

<table align=”right” border=”0″ >
<tr>
<th>
<div id=”contenedor_reloj”></div>
</th>
</tr>
</table>

Y con eso ya quedaria funcionando el reloj en su div correspondiente.

Ojala esta vez te resulte y si es asi, no olvides puntuar y cerrar la pregunta.

Saludos!

KoP 

Escribe un comentario

Tu comentario