生成四位带毫秒的时间格式

<?php

function microtime_float_my()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
/** 格式化时间戳,精确到毫秒,x代表毫秒 */
function microtime_format_my($tag, $time)
{
list($usec, $sec) = explode(".", $time);
$date = date($tag,$usec);
return str_replace('x', $sec, $date);
}
function get_rand_my()
{
$rand = '';
for($i=0;$i<=4;$i++)
{
$rand .= mt_rand(0,9);
}
return $rand;
}

function get_order_sn_my()
{
$now = microtime_float_my();
$string = "M".microtime_format_my("Ymdhisx",$now).get_rand_my();
$str = $string;
if(strlen($string)<24)
{
$str = str_pad($string,24,'0',STR_PAD_RIGHT);

}
return $str;
}

echo $order_sn = get_order_sn_my();
echo "<br>";
echo strlen($order_sn);

posted @ 2015-08-10 11:16  brady-wang  阅读(877)  评论(0编辑  收藏  举报