1. Utworzyć funkcję np.: showFullDescriptionTodayDate() - date() function
<?php
function showFullDescriptionTodayDate() {
$days_week = [ 'niedziela', 'poniedziałek', 'wtorek', 'środa',
'czwartek', 'piątek', 'sobota' ];
$months = [ '', 'stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca',
'lipca', 'sierpnia', 'września','października', 'listopada', 'grudnia' ];
$full_description = 'Dzisiaj jest - '.$days_week[date("w")].', '
.date("d").' '.$months[date("n")].', '.date("Y");
return $full_description;
}
?>
przykładowe użycie.
<?php
function showFullDescriptionTodayDate() {
$days_week = ['niedziela', 'poniedziałek', 'wtorek', 'środa',
'czwartek', 'piątek', 'sobota'];
$months = ['', 'stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca',
'lipca', 'sierpnia', 'września','października', 'listopada', 'grudnia'];
$full_description = 'Dzisiaj jest - '.$days_week[date("w")].', '
.date("d").' '.$months[date("n")].', '.date("Y");
return $full_description;
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
</head>
<body>
<div><?php echo showFullDescriptionTodayDate(); ?></div>
</body>
</html>
2. mktime() function, ponieważ
mktime() returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
<?php
$today = mktime(); // dzisiejsza data
$xmas = mktime(0,0,0,12,24,2020); // jak widać ;-)
$remained = floor(($xmas - $today) / 60);
?>
przykładowe użycie.
<?php
function minutesToXmas() {
define(MINUTE,60); // 60 sekund ;-)
$today = mktime(); // dzisiejsza data
$xmas = mktime(0,0,0,12,24,2020); // jak widać ;-)
$remained = floor(($xmas - $today) / MINUTE);
return ($remained > 0) ? $remained : 0;
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
</head>
<body>
<div>Pozostało <b><?php echo minutesToXmas(); ?></b> minut do 24 grudnia</div>
</body>
</html>
<?php
function minutesToXmas() {
define(MINUTE,60); // 60 sekund ;-)
$today = mktime(); // dzisiejsza data
$xmas = mktime(0,0,0,12,24,2020); // jak widać ;-)
$remained = floor(($xmas - $today) / MINUTE);
return ($remained > 0) ? $remained : 0;
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<style>
#minutes-to-xmas {
font-weight: bold;
}
</style>
</head>
<body>
<div>Pozostało <span id="minutes-to-xmas"><?php echo minutesToXmas(); ?></span> minut do 24 grudnia</div>
<script>
window.onload = () => {
const minutes_to_xmas = document.querySelector('#minutes-to-xmas');
const MINUTE_ = 60000;
const id_interval = setInterval(() => {
minutes_to_xmas.textContent--;
if (minutes_to_xmas.textContent == 0) clearInterval(id_interval);
}, MINUTE_);
}
</script>
</body>
</html>