http://ithelp.ithome.com.tw/question/10 ... g=nl.daily
今天想要比較日期
日期1跟日期2
差距在一分鐘秒內顯示差距xx秒
超過一分鐘了小於一小時顯示差距xx分鐘
超過一小時小於一天顯示差距xx小時
超過一天小於一個月顯示差距xx天
超過一個月小於一年顯示差距xx月
超過一年顯示差距xx年
請問該怎麼寫
function countdown ($date1, $date2) {
$difference = strtotime($date1) - strtotime($date2);
if ($difference > 31536000) {
$due_date = sprintf('差距%d年', floor($difference / 31536000));
} elseif ($difference > 2592000) {
$due_date = sprintf('差距%d月', floor($difference / 2592000));
} elseif ($difference > 86400) {
$due_date = sprintf('差距%d天', floor($difference / 86400));
} elseif ($difference > 3600) {
$due_date = sprintf('差距%d小時', floor($difference / 3600));
} elseif ($difference > 60) {
$due_date = sprintf('差距%d分鐘', floor($difference / 60));
} elseif ($difference > 0) {
$due_date = sprintf('差距%d秒', $difference);
} else {
$due_date = '---';
}
return $due_date;
}
PHP日期相距換算
前往
- Software
- ↳ CodeCharge Studio
- ↳ CodeCharge
- ↳ DemoCharge
- ↳ SuperPDF
- ↳ 551einv
- ↳ E3進銷存
- 程式語言
- ↳ PHP
- ↳ CodeLobster PHP Edition
- ↳ Yii
- ↳ CodeIgniter
- ↳ Phalcon
- ↳ Symfony
- ↳ FuelPHP
- ↳ Zend Framework 2
- ↳ laravel
- ↳ WordPress
- ↳ ASP.NET/C#
- ↳ ASP/VBScript
- ↳ JSP
- ↳ Java Servlets
- ↳ ColdFusion
- ↳ Perl
- ↳ Java Script
- ↳ jQuery
- ↳ HTML + CSS
- ↳ jQuery
- ↳ nodejs
- ↳ VB6
- ↳ Git
- ↳ App Inventor 2
- ↳ bash
- ↳ C++/ VC/ OpenCV
- ↳ OpenCV
- ↳ go
- ↳ cordova
- ↳ python
- ↳ Xamarin
- ↳ Assembly
- 資料庫
- ↳ MySQL
- ↳ PostgreSQL
- ↳ ORACLE
- ↳ Access
- ↳ SQL Server
- ↳ SQLite
- ↳ MariaDB
- ↳ Mongodb
- 作業系統
- ↳ Linux
- ↳ Ubuntu
- ↳ CentOS
- ↳ Mint
- ↳ Mandriva
- ↳ Debian
- ↳ Red Hat Enterprise Linux
- ↳ Oracle Linux
- ↳ Fedora
- ↳ Kali Linux
- ↳ OpenSUSE
- ↳ Elementary OS
- ↳ Microsoft
- ↳ Server 2008 R2
- ↳ Server 2012 R2
- ↳ Server 2012
- ↳ 8
- ↳ 10
- ↳ System Center 2016
- ↳ NOVELL
- ↳ FreeBSD
- ↳ VMware
- ↳ VirtualBox
- ↳ Mac OS X
- ↳ Solaris
- ↳ iOS
- ↳ Android
- ↳ Cloud
- ↳ OpenStack
- ↳ Docker
- ↳ Proxmox VE
- ↳ CloudReady
- ↳ chrome
- 網頁伺服器
- ↳ apache
- ↳ tomcat
- ↳ nginx
- ↳ IIS
- ↳ JBoss
- ↳ weblogic
- ↳ WebHosting
- 硬體
- ↳ 硬體及週邊
- ↳ RouterOS
- ↳ LEGO NXT
- ↳ Arduino
- ↳ MSP430
- ↳ Raspberry Pi
- ↳ OpenERP
- ↳ Storage
- ↳ Server
- ↳ Brocade
- ↳ MODELS
- ↳ FortiGate
- 軟體
- ↳ sublime
- ↳ LibreNMS