php strtotime 函数与实例教程

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

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

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

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

Returns a timestamp on success, FALSE www.111cn.netotherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

现在我们来看看strtotime字符转换成时间的函数实例

 

<?php教程
//function
function nextWeeksDay($date_begin,$nbrweek)
{
$nextweek=array();
for($i = 1; $i <= $nbrweek; $i++)  { // 52 week in one year of coursewww.111cn.net
$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 '<br> - '.$result[$i];
}
?>

<?php
$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);
}
?>
<?php
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"), " ";
?>

这是一个快速函数计算在一年期间,“工作天”。 “工作日”是指那些没有周末,没有假期在$数组中指定的假日。我离开了读者的实施超过1年。

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"));

时间: 2024-07-30 13:31:25

php strtotime 函数与实例教程的相关文章

php 获取文件大小函数与实例教程

php 获取文件大小函数与实例教程 <?php function getFileSize($url){ $url = parse_url($url); if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){ fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1rn"); fputs

oracle 字符长度函数及实例教程

oracle 字符长度函数及实例教程 -- Oracle 里面使用 lengthb SQL> select lengthb('123456') from dual; LENGTHB('123456') -----------------                 6 SQL> select lengthb('123456天津') from dual; LENGTHB('123456天津') ---------------------   mysql教程> select char_l

sql SUM()函数 求和实例教程

sql SUM()函数 求和实例教程,好了下面来看看吧. sum是用来求一列的数据之和的,必须是数值型的哦.下面来看看语法吧. SELECT SUM(column_name) FROM table_name 我们举个例子来说明一下吧. O_Id OrderDate OrderPrice Customer 1 2008/11/12 1000 Hansen 2 2008/10/23 1600 Nilsen 3 2008/09/02 700 Hansen 4 2008/09/03 300 Hansen

Python中zip()函数用法实例教程_python

本文实例讲述了Python中zip()函数的定义及用法,相信对于Python初学者有一定的借鉴价值.详情如下: 一.定义: zip([iterable, ...])zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个tuple(元组),然后返回由这些tuples组成的list(列表).若传入参数的长度不等,则返回list的长度和参数中长度最短的对象相同.利用*号操作符,可以将list unzip(解压). 二.用法示例: 读者看看下面的例子,对

jQuery中队列queue()函数的实例教程_jquery

如果当前jQuery对象匹配多个元素:获取队列时,只获取第一个匹配元素上的队列:设置队列(替换队列.追加函数)时,则为每个匹配元素都分别进行设置. 该函数属于jQuery对象(实例).如果需要移除并执行队列中的第一个函数,请使用dequeue()函数.你也可以使用clearQueue()函数清空指定的队列. 语法jQuery 1.2 新增该函数.queue()函数具有如下两种用法: 用法一: jQueryObject.queue( [ queueName ] [, newQueue ] ) 如果

判断字符长度函数strlen实例教程

定义和用法 该strlen ( )函数返回的长度字符串. 他的作用是计算字字符长度的,中文一个字为2 语法 strlen(string)   Parameter Description string Required. Specifies the string to check 来看个简单的例子吧.   <?php echo strlen("Hello world!"); ?>   输出为   12 以上是小编为您精心准备的的内容,在的博客.问答.公众号.人物.课程等栏目也

php mysql_connect 与mysql_pconnect函数与实例教程

 代码如下 复制代码 mysql_connect  mysql_connect($this->root,$this->user,$this->pass) /* mysql_connect ,单个反问用户不会频繁的调用数据库教程,没必要保持连接,而且mysql的连接数也是有限制的, 使用 及时访问比较频繁,也最好使用mysql_connect,这样使用的过的资源可以立刻释放,否则,容易造成资源耗 */ mysql_pconnect /* mysql_pconnect() 函数打开一个到 M

C语言循环结构与时间函数用法实例教程_C 语言

本文实例展示了C语言循环结构与时间函数用法,对于C语言的学习来说是非常不错的参考借鉴材料.分享给大家供大家参考之用.具体如下: 完整实例代码如下: /********************************************** ** <Beginning C 4th Edition> Notes codes ** Created by Goopand ** Compiler: gcc 4.7.0 *****************************************

PHP implode() 函数实例教程

 PHP implode() 函数实例教程 定义和用法  implode( )函数返回一个字符串的内容阵列. 语法 implode(separator,array)参数说明分隔可选.指定放什么东西到之间的数组元素.默认为" " (空字符串) 阵列必需的.阵列加入到一个字符串-------------------------------------------------- ------------------------------ 提示和说明注:implode( )函数接受其参数要么