例1
直接把日期转换
代码如下 | 复制代码 |
function daysbetweendates($date1, $date2){ |
例2
代码如下 | 复制代码 |
functionmaketime($date) ?> |
例3
PHP实现两个日期间隔的年、月、周、日数的计算
代码如下 | 复制代码 |
function format($a,$b){ //检查两个日期大小,默认前小后大,如果前大后小则交换位置以保证前小后大 if(strtotime($a)>strtotime($b)) list($a,$b)=array($b,$a); $start = strtotime($a); $stop = strtotime($b); $extend = ($stop-$start)/86400; $result['extends'] = $extend; if($extend $result['daily'] = $extend; }elseif($extend if($stop==strtotime($a.'+1 month')){ $result['monthly'] = 1; }else{ $w = floor($extend/7); $d = ($stop-strtotime($a.'+'.$w.' week'))/86400; $result['weekly'] = $w; $result['daily'] = $d; } }else{ $y= floor($extend/365); if($y>=1){ //如果超过一年 $start = strtotime($a.'+'.$y.'year'); $a = date('Y-m-d',$start); //判断是否真的已经有了一年了,如果没有的话就开减 if($start>$stop){ $a = date('Y-m-d',strtotime($a.'-1 month')); $m =11; $y--; } $extend = ($stop-strtotime($a))/86400; } if(isset($m)){ $w = floor($extend/7); $d = $extend-$w*7; }else{ $m = isset($m)?$m:round($extend/30); $stop>=strtotime($a.'+'.$m.'month')?$m:$m--; if($stop>=strtotime($a.'+'.$m.'month')){ $d=$w=($stop-strtotime($a.'+'.$m.'month'))/86400; $w = floor($w/7); $d = $d-$w*7; } } $result['yearly'] = $y; $result['monthly'] = $m; $result['weekly'] = $w; $result['daily'] = isset($d)?$d:null; } return array_filter($result); } print_r(format('2012-10-1','2012-12-15')); ?> |
教程地址:
欢迎转载!但请带上文章地址^^

PHP中的explode函数是一种用来将字符串分割成数组的函数,它非常常用且灵活。在使用explode函数的过程中,常常会遇到一些报错和问题,本文将介绍explode函数的基本用法并提供一些解决报错的方法。一、explode函数基本用法在PHP中,explode函数的基本语法如下:explode(string$separator,string$stri

标题:PHP中使用explode函数时常见的错误及解决方案在PHP中,explode函数是用于将字符串分割成数组的常用函数。然而,由于使用不当或者数据格式不正确,可能会导致一些常见的错误。本文将针对在使用explode函数时可能遇到的问题进行分析,并提供解决方案和具体的代码示例。错误一:未传入分隔符参数在使用explode函数时,最常见的错误之一是未传入分隔

在PHP编程中,处理字符串是一个经常需要进行的操作。其中,分割和合并字符串则是两种常见的需求。为了更方便地进行这些操作,PHP提供了两个非常实用的函数,即explode和implode函数。本文将介绍这两个函数的用法,以及一些实用的技巧。一、explode函数explode函数用于将一个字符串按照指定的分隔符进行分割,并返回一个数组。其函数原型如下:arra

使用PHP函数"explode"将字符串拆分为数组在PHP开发中,经常会遇到需要将一个字符串按照指定的分隔符进行拆分的情况。这时,我们可以使用PHP内置函数"explode"来实现字符串到数组的转换。本文将介绍如何使用"explode"函数来拆分字符串,并给出相关的代码示例。"explode"函数的基本语法如下:arrayexplode(

php explode报错的解决办法:1、找到并打开出错的PHP代码;2、找到explode函数部分;3、修改代码为“dump(explode(',',$str));die;”,也就是用逗号分割为数组即可。

使用PHP函数"explode"将字符串拆分为多个子字符串在PHP编程中,我们经常会遇到需要将一个字符串拆分为多个子字符串的情况。这时,PHP提供了一个非常方便的函数"explode",可以帮助我们轻松实现这个功能。"explode"函数的语法如下:arrayexplode(string$delimiter,string$string[,in

PHP中的时间戳处理:如何使用strtotime函数将日期时间转换为时间戳时间戳是指从1970年1月1日00:00:00(格林尼治时间)至今的秒数。在PHP中,我们经常需要在日期和时间之间进行转换,使得我们能够更方便地进行时间操作。PHP提供了strtotime函数来将日期时间转换为时间戳,下面让我们来看看如何正确使用strtotime函数。首先,让我们来看

在PHP语言中,有很多基础函数可以帮我们快速有效地处理字符串。其中,explode函数是一个很实用的字符串分割函数。它可以将一个字符串按照指定的分割符分割成数组,进而进行更为灵活的字符串操作。在本文中,我们将会介绍PHP中如何使用explode函数来分割字符串。一、explode函数格式explode函数在PHP语言中的格式如下:explode(separa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
