PHP
downloads | documentation | faq | getting help | mailing lists | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Introduzione> <Estensioni correlate a calendari ed eventi
Last updated: Fri, 18 Jul 2008

view this page in

Date and Time



add a note add a note User Contributed Notes
Date/Time
zoe at monkeehouse dot com
24-Oct-2008 10:52
Should you want to convert between HH:MM:SS and plain seconds like in MySQL, these functions should do the trick:

<?php
function time_to_sec($time) {
   
$hours = substr($time, 0, -6);
   
$minutes = substr($time, -5, 2);
   
$seconds = substr($time, -2);

    return
$hours * 3600 + $minutes * 60 + $seconds;
}

function
sec_to_time($seconds) {
   
$hours = floor($seconds / 3600);
   
$minutes = floor($seconds % 3600 / 60);
   
$seconds = $seconds % 60;

    return
sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
}
?>
JonathanCross.com
25-Jul-2008 08:13
<?php
// A demonstration of the new DateTime class and the
// fact that it fixes dates before 1970 and after 2038.
?>
<h2>PHP 2038 date bug demo (php version <?=phpversion()?>)</h1>
<div style='float:left;margin-right:3em;'>
<h3>OLD Buggy date()</h3>
<?
for ( $i = 1900; $i < 2050; $i++) {
 
$datep = "$i-01-01";
  print
"  Trying: $datep ... ";
  print
date("F j, Y", strtotime($datep));
  print
"<BR>";
}
?></div>
<div style='float:left;'>
  <h3>NEW DateTime Class (v 5.2+)</h3><?
 
for ( $i = 1900; $i < 2050; $i++) {
   
$datep = "$i-01-01";
   
$date = new DateTime($datep);
    print
"  Trying: $datep ... ";
    print
$date->format('F j, Y');
    print
"<BR>";
  }
?></div>

Introduzione> <Estensioni correlate a calendari ed eventi
Last updated: Fri, 18 Jul 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites