真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

javascript、php與mysql時(shí)間格式化函數(shù)

  1. javascript:
    /*
    @desc:時(shí)間友好顯示函數(shù)
    @param stamp 時(shí)間綴,10位長(zhǎng)度
    */
    function timefriend(stamp){
    this.stamp = stamp
    /*
     @desc:主方法,執(zhí)行轉(zhuǎn)換
     */
    this.get = function(){
        var stamp = this.stamp
        if(!stamp){
            return '—';
        }
        var date = new Date(stamp*1000)
        var time = Math.round(new Date().getTime()/1000)
        diff = time - stamp
        if(diff<0){
            return '—';
        }else if(diff<60){
            return diff+'秒前'
        }else if(diff<3600){
            return Math.floor(diff/60)+'分鐘前'
        }else if(diff<86400){
            return Math.floor(diff/3600)+'小時(shí)前'
        }else if(diff<259200){
            return Math.floor(diff/86400)+'天前'
        }else{
            var year = this.parsetime(date.getFullYear())
            var month = this.parsetime(date.getMonth())
            var day = this.parsetime(date.getDate())
            var hour = this.parsetime(date.getHours())
            var minute = this.parsetime(date.getMinutes())
            var second = this.parsetime(date.getSeconds())
            var ret = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second
            return ret
        }
    }
    this.parsetime = function(input){
        var ret
        if(input >= 0 && input < 10){
            ret = '0'+input
        }else{
            ret = input
        }
        return ret
    }
    }
    var timefriend = new timefriend('1428593779')
    console.log(timefriend.get())
  2. php:
    /*
    @desc:顯示某一個(gè)時(shí)間相當(dāng)于當(dāng)前時(shí)間在多少秒前,多少分鐘前,多少小時(shí)前
    @param  stamp      時(shí)間戳
    @param  format     時(shí)間顯示格式,默認(rèn)Y-m-d H:i:s
    @return 如      5秒前
    */
    function timefriend($stamp,$format = 'Y-m-d H:i:s'){
    if(empty($stamp)||!is_numeric($stamp)||!$stamp){
        return '—';
    }
    $diff = time() - $stamp;
    if($diff<0){
        return '—';
    }elseif($diff<60){
        return $diff.'秒前';
    }elseif($diff<3600){
        return floor($diff/60).'分鐘前';
    }elseif($diff<86400){
        return floor($diff/3600).'小時(shí)前';
    }elseif($diff<259200){
        return floor($diff/86400).'天前';
    }else{
        return date($format,$stamp);
    }
    }
  3. MySQL:
    DELIMITER //
    CREATE FUNCTION friendlyDate(sTime char(11))
    RETURNS char(11)
    BEGIN
    if sTime='' then
        return '-';
    end if;
    set @cTime=UNIX_TIMESTAMP();
    set @dTime=@cTime-sTime;
    set @dDay=DATE_FORMAT(@cTime,'%e')-DATE_FORMAT(@sTime,'%e');
    set @dYear=DATE_FORMAT(@cTime,'%Y')-DATE_FORMAT(@sTime,'%Y');
    if @dTime>0 then
        if @dTime<60 then
            if @dTime<10 then
                return '剛剛';
            else
                set @t=floor(@dTime/10)*10;
                set @ret=concat(@t,'秒前');
                return @ret;
            end if;
        elseif @dTime<3600 then
            set @t=@dTime/60;
            set @ret=concat(@t,'分鐘前');
            return @ret;
        elseif @dYear=0 && @dDay=0 then
            set @t=DATE_FORMAT(@sTime,'%H:%i');
            set @ret=concat('今天',@t);
            return @ret;
        elseif @dYear=0 then
            return DATE_FORMAT(@sTime,'%m月%d日 %H:%i');
        else
            return DATE_FORMAT(@sTime,'%Y-%m-%d %H:%i:%s');
        end if;
    else
        return DATE_FORMAT(@sTime,'%Y年%m月%d日 %H:%i');
    end if;
    END
    //
    DELIMITER ;

分享題目:javascript、php與mysql時(shí)間格式化函數(shù)
分享地址:http://weahome.cn/article/jcoijj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部