zoukankan      html  css  js  c++  java
  • 获取毫秒时间戳

    time.php:

    <?php
    abstract class Millisecond {
    
        private $defaultDigit;
    
        public function __construct($_digit = 4)
        {
            $this->defaultDigit = $_digit;
        }
    
        /* 
         * 
         * @param $digit 毫秒的位数,0表示不使用毫秒
         */  
        final function get_time()  
        {
            $counter = $this->defaultDigit;
            if(!$counter) return time();
    
            if ($counter != 3) {
                $tmp_time = 10;
                while(--$counter) {
                    $tmp_time *= 10;
                }
            } else {
                $tmp_time = 1000;
            }
    
            $time = explode (" ", microtime());
            $time = $time[1] . ($time[0] * $tmp_time);   
            $time = explode ( ".", $time );   
            $time = $time[0];
    
            return $time;  
        }
    
        /**
         * 计算时间位数
         * @param  [type] $time [description]
         * @return [type]       [description]
         */
        final function calcDigit($time)
        {
            return strlen($time);
        }
    
        /**
         * 根据指定位数,判断是否可以使用
         * @param  [type]  $digit [description]
         * @return boolean        [description]
         */
        final function isOutput($digit)
        {
            if(($this->defaultDigit + 10) == $digit) return true;
            else return false;
        }
    
        /**
         * 获取时间戳
         * @param  [type] $count [description]
         * @return [type]        [description]
         */
        abstract function getMillisecond();
    }

    mytime.php:

    <?php
    require "./time.php";
    
    class MyTime extends Millisecond{
    
        public function __construct($_digit = 5)
        {
            parent::__construct($_digit);
        }
    
        public function getMillisecond(){
            $time = $this->get_time();
            if ($this->isOutput($this->calcDigit($time))) {
                return $time;
            } else {
                return $this->getMillisecond();
            }
        }
    }
    
    $mytime = new MyTime();
    
    echo $mytime->getMillisecond();
  • 相关阅读:
    firstresponder 后,键盘不显示
    performSelector
    setNeedsDisplay、setNeedsLayout 区别
    Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
    GCD介绍(一):基本概念和dispatch queues
    一些概念
    /mnt/sdcard /sdcard
    eclipse 导入已存在的工程文件出错
    ios 常用技巧
    ios nsstring去掉换行符
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/6743720.html
Copyright © 2011-2022 走看看