posts - 82, comments - 269, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

常用PHP时间函数

Posted on 2007-10-16 22:57 itspy 阅读(294) 评论(0)  编辑  收藏

/**formate datetime to timestamp**/
function convert_datetime($str) {
 list($date, $time) = explode(' ', $str);
 list($year, $month, $day) = explode('-', $date);
 list($hour, $minute, $second) = explode(':', $time);
 $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
 return $timestamp;
}

/**formate timestamp to datetime **/
function convert_timestamp ($timestamp)
{
 return   strftime ("%Y-%m-%d %H:%M:%S", $timestamp); 
 
}

/**formate m/d/y to datetime, in order to store to DB**/

function getDateTime($strtime){


 $array = explode("/",$strtime);

 $month = $array[0];
 $day = $array[1];
 $year = $array[2];

 #int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )
 
 $timestamp =mktime(0,0,0,$month,$day,$year);
 
 return convert_timestamp($timestamp);
}


只有注册用户登录后才能发表评论。


网站导航: