| Autor | Zpráva | ||
|---|---|---|---|
| Welton123 Profil |
#1 · Zasláno: 18. 7. 2013, 15:28:09
Dobrý den, mám tento php script:
<meta http-equiv="refresh" content="1;url=odpocet.php">
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Julian P.
* All rights reserved
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class countdown {
protected $year;
protected $month;
protected $day;
protected $hour;
protected $minute;
protected $second;
protected $format;
/*
* constructor initializes the countdown-object
*
* @param int $year
* @param int $month
* @param int $day
* @param int $hour
* @param int $minute
* @param int $second
* @param string $format
*
* return void
*/
function __construct($year=NULL, $month=NULL, $day=NULL, $hour=NULL, $minute=NULL, $second=NULL, $format=NULL) {
if($year == NULL) { $this->year = date('Y'); } else { $this->year = $year; }
if($month == NULL) { $this->month = date('m'); } else { $this->month = $month; }
if($day == NULL) { $this->day = date('d'); } else { $this->day = $day; }
if($hour == NULL) { $this->hour = 0; } else { $this->hour = $hour; }
if($minute == NULL) { $this->minute = 0; } else { $this->minute = $minute; }
if($second == NULL) { $this->second = 0; } else { $this->second = $second; }
if($format == NULL) { $this->format = '%y %m %d %h %m'; } else { $this->format = strtolower($format); }
}
/*
* set the year of the specific date
*
* @param int $year
*
* return void
*/
public function setYear($year) {
$this->year = $year;
}
/*
* get the year of the specific date
*
* return int
*/
protected function getYear() {
return $this->year;
}
/*
* set the month of the specific date
*
* @param int $month
*
* return void
*/
public function setMonth($month) {
$this->month = $month;
}
/*
* get the month of the specific date
*
* return int
*/
protected function getMonth() {
return $this->month;
}
/*
* set the day of the specific date
*
* @param int $day
*
* return void
*/
public function setDay($day) {
$this->day = $day;
}
/*
* get the day of the specific date
*
* return int
*/
protected function getDay() {
return $this->day;
}
/*
* set the hour of the specific date
*
* @param int $hour
*
* return void
*/
public function setHour($hour) {
$this->hour = $hour;
}
/*
* get the hour of the specific date
*
* return int
*/
protected function getHour() {
return $this->hour;
}
/*
* set the minute of the specific date
*
* @param int $minute
*
* return void
*/
public function setMinute($minute) {
$this->minute = $minute;
}
/*
* get the minute of the specific date
*
* return int
*/
protected function getMinute() {
return $this->minute;
}
/*
* set the second of the specific date
*
* @param int $second
*
* return void
*/
public function setsecond($second) {
$this->second = $second;
}
/*
* get the second of the specific date
*
* return int
*/
protected function getSecond() {
return $this->second;
}
/*
* set the format of the output
*
* @param string $format
*
* return void
*/
public function setFormat($format) {
$this->format = $format;
}
/*
* get the format of the output
*
* return string
*/
protected function getFormat() {
return $this->format;
}
/*
* get the remaining time by given date/time
*
* return string
*/
public function getTimeRemaining() {
$start = time();
$end = mktime($this->getHour(), $this->getMinute(), $this->getSecond(), $this->getMonth(), $this->getDay(), $this->getYear());
$span = ($end-$start);
if( strstr($this->format, '%d') ) {
$oneDay = (60 * 60 * 24);
$day = floor($span / $oneDay);
$span = $span % $oneDay;
$this->setFormat( str_replace('%d', $day, $this->getFormat()) );
}
if( strstr($this->format, '%h') ) {
$oneHour = (60 * 60);
$hour = floor($span / $oneHour);
$span = $span % $oneHour;
$this->setFormat( str_replace('%h', $hour, $this->getFormat()) );
}
if( strstr($this->format, '%m') ) {
$minute = floor($span / 60);
$this->setFormat( str_replace('%m', $minute, $this->getFormat()) );
}
if( strstr($this->format, '%s') ) {
$second = $span % 60;
$this->setFormat( str_replace('%s', $second, $this->getFormat()) );
}
return $this->getFormat();
}
}
// ----
// ---- EXAMPLE ---- EXAMPLE ---- EXAMPLE ---- EXAMPLE ---- EXAMPLE ---- EXAMPLE ---- EXAMPLE ----
// ----
$c = new countdown();
/*
* Posibilities:
* -> %d = days
* -> %h = hours
* -> %m = minutes
* -> %s = seconds
*/
$c->setFormat('%d dní, %h hodin, %m minut a %s sekund!');
$c->setDay(19);
$c->setMonth(7);
$c->setYear(2013);
$c->setHour(14); // optional
$c->setMinute(50); // optional
$c->setSecond(0); // optional
print $c->getTimeRemaining(0);
?>Vše funguje jak má, ale nevím, jak přidat, aby po uplynutí času se čas nepočítal do mínusu, ale aby se např. místo odpočtu ukázala hláška "čas uplynul" Předem děkuji |
||
| _es Profil |
#2 · Zasláno: 18. 7. 2013, 17:02:02
Welton123:
<meta http-equiv="refresh" content="1;url=odpocet.php"> |
||
| Welton123 Profil |
#3 · Zasláno: 18. 7. 2013, 18:44:37
Tím aktualizuji ten soubor pouze.
Poté je celý soubor do indexu vložen přes iframe. |
||
|
Časová prodleva: 13 let
|
|||
0