本文实例讲述了php中strtotime函数用法。分享给大家供大家参考。具体如下:

strtotime(字符串$时间[,诠释$现在])int strtotime(string $time [,int $now] 该函数期望得到一个包含美国英语日期格式,并会尝试解析成一个Unix时间戳(多少秒自1970年1月1日00:00:00星期一该格式),相对于现在提供的时间戳,或当前时间如果现在不提供

这个函数将使用TZ环境变量(如果有)来计算时间戳,自PHP 5.1.0有更容易的方法来确定所使用的所有/日期时间函数的时区,这一过程是解释在date_default_timezone_get()函数的一页.

解析的字符串,在PHP 5.0.0,不允许在微秒的时间,自PHP 5.0.0他们是允许的,但忽略.

现在哪些是作为计算基数相对日期使用时间戳.

返回值:在成功返回一个时间戳,否则返回FALSE,前到PHP 5.1.0,这个函数将返回失败-1.

现在我们来看看strtotime字符转换成时间的函数实例,代码如下:

//function

function nextWeeksDay($date_begin,$nbrweek)

{

$nextweek=array();

for($i = 1; $i <= $nbrweek; $i++)  { // 52 week in one year of coursewww.phpfensi.com

$nextweek[$i]=date('D d M Y', strtotime('+'.$i.' week',$date_begin));

}

return $nextweek;

}

/// end function

/// example of a select date

// var

$date_begin = strtotime('06-05-2010'); //D Day Month Year  - like function format.

$nbrweek=52;

// call function

$result=nextWeeksDay($date_begin,$nbrweek);

// Preview

for($i = 1; $i <= $nbrweek; $i++)  {

echo '
- '.$result[$i];

}

?>

$str = 'Not Good';

// previous to PHP 5.1.0 you would compare with -1, instead of false

if (($timestamp = strtotime($str)) === false) {

echo "The string ($str) is bogus";

} else {

echo "$str == " . date('l dS o F Y h:i:s A', $timestamp);

}

?>

echo strtotime("now"), " ";

echo strtotime("10 September 2000"), " ";

echo strtotime("+1 day"), " ";

echo strtotime("+1 week"), " ";

echo strtotime("+1 week 2 days 4 hours 2 seconds"), " ";

echo strtotime("next Thursday"), " ";

echo strtotime("last Monday"), " ";

?>

这是一个快速函数计算在一年期间,“工作天”,“工作日”是指那些没有周末,没有假期在$数组中指定的假日,实例代码如下:

function get_working_days($to_date) {

$holidays = array(

1 => array(10), //2011 ...

2 => array(11),

3 => array(21), //... 2011

4 => array(29,30), //2010 ...

5 => array(3,4,5),

6 => array(),

7 => array(19),

8 => array(11,12,13),

9 => array(20,23),

10 => array(11),

11 => array(3,23),

12 => array(23) //... 2010

);

for($to_date, $w = 0, $i = 0, $x = time(); $x < $to_date; $i++, $x = strtotime("+$i day")) {

if(date("N",$x) < 6 &! in_array(date("j",$x),$holidays[date("n",$x)])) $w++;

}

return $w;

}

//Usage:

echo get_working_days(strtotime("2011-01-08"));

希望本文所述对大家的PHP程序设计有所帮助。

php中strtotime的意思,php中strtotime函数用法详解相关推荐

  1. C++中substr()函数用法详解

    C++中substr()函数用法详解 原型: string substr (size_t pos = 0, size_t len = npos) const; 返回一个新构造的string对象,其值初 ...

  2. c++ memset 语言_C++中memset函数用法详解

    本文实例讲述了C++中memset函数用法.分享给大家供大家参考,具体如下: 功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值,块的大小由第三个参数指定,这个函数通常 ...

  3. python中mat函数_Python中flatten( )函数及函数用法详解

    flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个一维数组. flatten只能适用于numpy对象,即array或者mat,普通的list列 ...

  4. python中import re_Python3中正则模块re.compile、re.match及re.search函数用法详解

    本文实例讲述了Python3中正则模块re.compile.re.match及re.search函数用法.分享给大家供大家参考,具体如下: re模块 re.compile.re.match. re.s ...

  5. python中isinstance怎么用_pythonisinstance函数用法详解

    这篇文章主要介绍了python isinstance函数用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 isinstance() 函数来判断 ...

  6. python explode_pandas dataframe 中的explode函数用法详解

    在使用 pandas 进行数据分析的过程中,我们常常会遇到将一行数据展开成多行的需求,多么希望能有一个类似于 hive sql 中的 explode 函数. 这个函数如下: Code # !/usr/ ...

  7. python中setattr()函数用法详解

    setattr() 函数对应函数 getattr(),用于设置属性值,该属性不一定是存在的. getattr()用法详见博文:python中getattr()函数用法详解_IT之一小佬的博客-CSDN ...

  8. python six模块详解_对python中的six.moves模块的下载函数urlretrieve详解

    实验环境:windows 7,anaconda 3(python 3.5),tensorflow(gpu/cpu) 函数介绍:所用函数为six.moves下的urllib中的函数,调用如下urllib ...

  9. python中count的作用_python count函数用法详解

    在python中可以使用"count()"函数统计字符串里某个字符出现的次数,该函数用于统计次数,其语法是"count(sub, start= 0,end=len(str ...

  10. sort在c语言中的作用,c语言中sort的用法详解.docx

    c语言中sort的用法详解.docx C语言中SORT的用法详解C语言的学习很多是比较复杂的,那么C语言中SORT的用法的用法你知道吗下面学习啦小编就跟你们详细介绍下C语言中SORT的用法的用法,希望 ...

最新文章

  1. 蓝桥杯 入门训练 试题集汇总 【A+B问题、序列求和、圆的面积、Fibonacci数列】
  2. 视频讲解——零基础玩转微信小程序
  3. 100行代码撸完SpringIOC容器
  4. 依码仕喷码机编程指南
  5. typecho博客,typecho插件,typecho博客搭建
  6. PIM是什么意思,如何做好企业产品信息管理?
  7. Synchronized 用法以及和ReetrantLock的区别
  8. 青龙面板 企业微信应用推送
  9. Git首次提交代码到远程仓库时,出现fatal: unable to access ‘https://github.com/xxx/xxx.git/‘
  10. 李学江:B2B行业门户网站最终页标题设置方法
  11. Win11无线适配器或访问点有问题怎么解决?
  12. TI培训——电子电路基础知识讲座(第三章上)
  13. IOT数字世界价值论(下)
  14. CPP-week thirteen
  15. day02【Collection、泛型】-笔记
  16. 星起航:抖音小店达人关系日常维护
  17. 海康威视摄像机SDK二次开发--通过云台参数设置控制摄像机的位置
  18. centos7部署openstack(queens)
  19. 光学工程毕业论文题目【必看】
  20. 【单相桥式全控整流电路求解纲要】单相桥式全控整流电路,U2=100V,负载中R=2Ω,L值极大,反电势E=60V,当a=30度时,分析电路

热门文章

  1. python续行符是啥_python续行符
  2. python获取get请求的耗时时间_突破python爬取极限,超牛逼的异步协程爬虫
  3. 9年当上架构师,我的很多想法变了
  4. gel和react哪个厉害_gel、react、boost三种材料的跑鞋,哪个更强?
  5. VS Code Pettier设置换行最大宽度
  6. php 打印变量内存地址_Python合集之Python变量
  7. es6 Set 结合 Array.from 用法
  8. mac版sublime 无法下载插件(Vue 代码无高亮问题)
  9. swiper轮播图插件
  10. bootstrap3中模态框的数据编辑使用方法