«

时间函数和异常处理

时间:2023-3-1 21:56     作者:wen     分类: PHP


<?php
   /*
      时间函数
      time 得到的是1970到现在的秒数
      date 格式化当前时间戳
      date_default_timezone_set('Asia/shanghai');设置时区
      echo date_default_timezone_get(); 获取时区
      getdate() 获取当前的日期及时间信息 array
      checkdate(month, day, year) 验证一个日期是否合法 bool
      echo mktime()生产一个1970年到指定日期的时间戳
      strtotime(time) now 
      microtime() 获得时间戳及微秒数
      bcadd()
    */
   date_default_timezone_set('Asia/shanghai');
   echo date_default_timezone_get();
   echo time();
   echo '<br />';
   echo date('Y-m-d H:i:s',time());
   echo '<hr />';
   print_r(getdate());
   var_dump(checkdate(11, 3, 2016));
   echo mktime(8,8,8,8,8,2008);
   echo '<br/>';
   echo strtotime('now');
   echo date('Y-m-d H:i:s',strtotime('-1 week'));
   echo '<br/>';
   echo microtime();

   /*
      错误处理函数
      方法一 die() @
      方法二 定义错误处理函数
            set_error_handler()
      方法三 error_log()
      file_exists()
      include 引文件
    */
   if(!file_exists('7.php')){
      die('no this file');
   }else{
      include('7.php');
   }
   // function dealError($level,$message){
   //     die('错误等级:'.$level.'<br/>错误消息'.$message);
   // }   

   // set_error_handler('dealError');
   // include ('5.php');
   // echo 123;
   if(!file_exists('7.php')){
      error_log('文件名错误',3,'D:PHP/errorLog.txt');
   }else{
      include('7.php');
   }
   try {

   } catch (Exception $e) {

   }catch (Exception $e) {

   }catch (Exception $e) {

   }catch (Exception $e) {

   }
?>

标签: PHP基础