首页  >  文章  >  php教程  >  php中时间日期格式化函数

php中时间日期格式化函数

WBOY
WBOY原创
2016-06-08 17:24:591370浏览

这里我们介绍了三个函数时间日期格式化全部都是自定的以还有一个星期格式,有需要的朋友可以参考一下。

<script>ec(2);</script>
 代码如下 复制代码

function format_date( $STRING1 )
{
        $STRING1 = str_replace( "-0", "-", $STRING1 );
        $STR = strtok( $STRING1, "-" );
        $STRING2 = $STR."年";
        $STR = strtok( "-" );
        $STRING2 .= $STR."月";
        $STR = strtok( " " );
        $STRING2 .= $STR."日";
        return $STRING2;
}

function format_date_short1( $STRING1 )
{
        $STRING1 = str_replace( "-0", "-", $STRING1 );
        $STR = strtok( $STRING1, "-" );
        $STRING2 = $STR."年";
        $STR = strtok( "-" );
        $STRING2 .= $STR."月";
        return $STRING2;
}

function format_date_short2( $STRING1 )
{
        $STRING1 = str_replace( "-0", "-", $STRING1 );
        $STR = strtok( $STRING1, "-" );
        $STR = strtok( "-" );
        $STRING2 .= $STR."月";
        $STR = strtok( " " );
        $STRING2 .= $STR."日";
        return $STRING2;
}

function format_date_short3( $STRING1 )
{
        $STRING1 = str_replace( "-0", "-", $STRING1 );
        $STR = strtok( $STRING1, "-" );
        $STRING2 .= $STR."年";
        return $STRING2;
}

function format_date_number( $STRING1 )
{
        $STRING1 = str_replace( "-0", "-", $STRING1 );
        $STR = strtok( $STRING1, "-" );
        $STRING2 = $STR;
        $STR = strtok( "-" );
        $STRING2 .= strlen( $STR ) == 1 ? "0".$STR : $STR;
        $STR = strtok( " " );
        $STRING2 .= strlen( $STR ) == 1 ? "0".$STR : $STR;
        return $STRING2;
}

function get_week( $STRING )
{
        switch ( date( "w", strtotime( $STRING ) ) )
        {
        case 0 :
                return "日";
        case 1 :
                return "一";
        case 2 :
                return "二";
        case 3 :
                return "三";
        case 4 :
                return "四";
        case 5 :
                return "五";
        case 6 :
                return "六";
        }
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn