php 常用日期相函数[日期加减,两日期之差,日期转换时间截]

 更新时间:2016年11月25日 16:02  点击:2126
php 常用日期相函数[日期加减,两日期之差,日期转换时间截]

下面这些代码是一些常用的日期处理函数了,可以两个时间的日期加减,两日期之差,日期转换时间截等。

echo date('Y-m-d',strtotime('+1 d',strtotime('2009-07-08')));//日期天数相加函数

echo date("Y-m-d",'1246982400');
echo '<br>';
echo date("Y-m-d",'1279123200');
die();

$d   =   "2009-07-08 10:19:00";  
echo   date("Y-m-d",strtotime("$d   +1   day"));   //日期天数相加函数
 

function dateToTime($d)//把日期转换成时间堆截
{
 $year=((int)substr("$d",0,4));//取得年份

 $month=((int)substr("$d",5,2));//取得月份
 
 $day=((int)substr("$d",8,2));//取得几号
 
 return mktime(0,0,0,$month,$day,$year);
}


/*

下面函数计算两日期之着

*/

$Date_1="2009-07-08";

echo $Date_1+1;
 
$Date_2="2009-06-08";
$Date_List_a1=explode("-",$Date_1);
 
$Date_List_a2=explode("-",$Date_2);

$d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);

$d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);

$Days=round(($d1-$d2)/3600/24);

echo  "两日期之前相差有$Days 天"; 

本站原创转载注明来自www.111cn.net/phper/php.html

php 去除数组空值


我们要使用教程中经常会看到关于如何去除php数据中的空值了,下面我们提供二种去除空值的方法
$t=",,,,中国WEB第一站,www.111cn.net"
$ar= explode(',',$t);

function filter($var)
{
 if($var == '')
 {
  return false;
 }

return true;
}

array_filter($ar, "filter");

/*
foreach( $ar as $temp=>$k)
{
 if( $k )
 {   
         unset( $ar[$k] );   
 }   

}
print_r( $ar );
*/

上面函数得出的结果为
中国WEB第一站,www.111cn.net

本站原创转载注明来自www.111cn.net/phper/php.html

php 时间转换日期与日期转换成时间


<?php
$d ='2009-07-02 09:09:00';
echo date("Y-m-d",'1246606382');
echo date('Ymd',dateToTime($d));


$temp = dateToTime($d);
echo $temp;
echo date("Y-m-d",$temp);

function dateToTime($d)
{
 $year=((int)substr("$d",0,4));//取得年份

 $month=((int)substr("$d",5,2));//取得月份
 
 $day=((int)substr("$d",8,2));//取得几号
 
 return mktime(0,0,0,$month,$day,$year);
}
?>

php 简单file_get_contents fopen教程

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<?php
 $content =file_get_contents('http://down.111cn.net/');
 if( !empty( $content ) ){
  $info = fopen('down.txt','w+');
  fwrite($info,$content);
  fclose($info);
  print_r(file('down.txt') );
 }

 ?>
</body>
</html>

dedecms ajax 下载统计代码

<?php
require_once (dirname(__FILE__) . "/include/common.inc.php");
require_once(DEDEINC."/channelunit.class.php");

 $aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;
 
  $rand =mt_rand(10,80);
  
  $query = "select count(*) as dd from #@__downloads where id='$aid'";
  
  $row = $dsql->GetOne($query); 
 
  if($row['dd'] > 0)
  {
   $query = "update #@__downloads set downloads=downloads+$rand where id='$aid'";
   $dsql->ExecNoneQuery($query);
  }else {
   $query = "insert into #@__downloads(hash,id,downloads) values('null$aid','$aid',1)";
   $dsql->ExecNoneQuery($query);
  }
  

下面是实例方法。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://pstatic.xunlei.com/js/webThunderDetect.js"></script>
<script src="http://pstatic.xunlei.com/js/base64.js"></script>
<script language="javascript"  type="text/javascript">
var xmlHttp = false;

function ajaxcreate(){

try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
try {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (e2) {
  xmlHttp = false;
 }
 }

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
 }
if(!xmlHttp){alert('Create Xmlhttp Fail ');return false;}
}


function ajax_add(){ 
 ajaxcreate();
 var url="/ajax_down.php?aid="+encodeURI(5396)+"&rd="+Math.random();
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 xmlHttp.send(null); 
}

</script>
<title>绿色版Apache+Php+Mysql V1.3 自动安装版_下载地址列表_网站源码下载-整站源码下载-站长常用工具下载</title>
<link href="/templets/style/search.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<div class="header">
 <div class="toplogo">
  <h1><a href="http://down.111cn.net/">网站源码下载-整站源码下载-站长常用工具下载</a></h1>
 </div>
</div>

<div class="msgbar">
 <p>
  <strong>软件名称:<a href='/down/soft/server/2009/0629/5396.html'>绿色版Apache+Php+Mysql V1.3 自动安装版</a></strong>
 </p>
</div>
<div class="advancedsearch">
  <table width="100%" border="0" align="center" cellspacing="2">
    <tr>
      <td height="30" bgcolor="#F2F7E6">下载地址列表:</td>
    </tr>
    <tr>
      <td height="78"><script language="javascript" src="/js/gg_bottom.js"></script>
<a href="#" class="red" thunderHref="thunder://QUFodHRwOi8vemp0ZWxlNC5za3ljbi5jb20vZG93bi9nZ2dBUE1zZXJ2ZXIuemlwWlo=" thunderPid="85957" thunderType="" thunderResTitle="" onClick="ajax_add();return OnDownloadClick_Simple(this,2);" oncontextmenu="ThunderNetwork_SetHref(this)" >[迅雷专用下载]</a>

<script type="text/javascript"><!--
google_ad_client = "pub-6219414158063594";
/* 336x280, 创建于 09-3-29 */
google_ad_slot = "8019903307";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<script type="text/javascript"><!--
  google_ad_client = "pub-6219414158063594";
  google_ad_format = "configurable_sdo";
  google_link_target = 2;
  google_color_bg = "ffffff";
  google_color_link = "000000";
  google_color_text = "000000";
  google_encoding = "GB2312";
  google_ad_channel = "5161927073";
  google_box_len = 40;
  google_logo_pos = "left";
  google_rs_pos = "below";
  google_ad_height = 65;
  google_ad_width = 500;
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_sdo.js">
</script>

</td>
    </tr>
  </table>
</div>
<div class="footer">
<p class="link">
  网站版权信息及免责声明
  </p>

 <p class="powered">
  Copyright <a href="http://down.111cn.net" title="" target="_blank"><strong>down.<span>111cn.net</span></strong></a> &copy; 2004-2008  Inc.
<script language="javascript" src="/js/count.js"></script> 
</p><!-- /powered -->
 
</div>
<div id="tt" ></div>

</body>
</html>
 

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • 在java中获取List集合中最大的日期时间操作

    这篇文章主要介绍了在java中获取List集合中最大的日期时间操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-15
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • 教你怎么用Java获取国家法定节假日

    这篇文章主要介绍了教你怎么用Java获取国家法定节假日,文中有非常详细的代码示例,对正在学习java的小伙伴们有非常好的帮助,需要的朋友可以参考下...2021-04-23
  • mysql中获取一天、一周、一月时间数据的各种sql语句写法

    创建表:复制代码 代码如下:create table if not exists t( id int, addTime datetime default '0000-00-00 00:00:00′)添加两条初始数据:insert t values(1, '2012-07-12 21:00:00′);insert t values(2, '2012-07...2014-05-31
  • .NET/C# 使用Stopwatch测量运行时间

    这篇文章主要介绍了.NET/C# 使用Stopwatch测量运行时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • PostgreSQL 字符串处理与日期处理操作

    这篇文章主要介绍了PostgreSQL 字符串处理与日期处理操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-01
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • php计算两个日期相差天数的方法

    本文实例讲述了php计算两个日期相差天数的方法。...2015-03-15