日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php日期转微秒,使用PHP生成独特的微秒级

發(fā)布時(shí)間:2023/12/8 php 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php日期转微秒,使用PHP生成独特的微秒级 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

PHP中的time()函數(shù)返回當(dāng)前的Unix時(shí)間戳, 這是從 Unix時(shí)代的秒數(shù)開始測(cè)量的時(shí)間, 在某些情況下非常有用,但并非總是如此。與大多數(shù)其他PHP函數(shù)一樣,此函數(shù)也是跨平臺(tái)兼容的,因?yàn)樗m用于Unix,Linux,Windows和Mac。

PHP函數(shù)的 microtime()更精確和更精細(xì),因?yàn)樗晕⒚敕祷禺?dāng)前的Unix時(shí)間戳, 我們的問題是它返回一個(gè)包含空格和點(diǎn)的字符串,例如,如果您從PHP中生成文件名或HTML或CSS標(biāo)識(shí)符的一部分,那么這個(gè)字符串不是很有用。

這就是為什么我們?cè)谙旅鎸懥诉@么個(gè)小而有用的函數(shù), 它基于PHP函數(shù) microtime (),但是,返回一個(gè)干凈的數(shù)字字符串。

請(qǐng)享用!<?php /**

* Generates and returns a string of digits representing the time of the

* current system in microseconds granularity.

*

* Compared to the standard time() function, the microtime() function is more

* accurate and in addition, successive quick calls inside a loop generate

* unique results; which can be quite useful in certain cases.

*

* Our function below generates digits only output based on the time stamp

* generated by the microtime() function.

*

* @return string

*/functionget_clean_microtimestamp_string() {//Get raw microtime (with spaces and dots and digits)$mt=microtime();//Remove all non-digit (or non-integer) characters$r="";$length=strlen($mt);

for($i=0;$i

if(ctype_digit($mt[$i])) {$r.=$mt[$i];

}

}//Returnreturn$r;

}

注意,microtime()僅在支持gettimeofday()系統(tǒng)調(diào)用的操作系統(tǒng)上可用, 我們?cè)?Windows 7. Windows 8 和Ubuntu14上測(cè)試了它,它們上都能正常工作。

注意microtime()會(huì)產(chǎn)生一個(gè)不同的輸出值,即使是連續(xù)多次調(diào)用, 你自己試試吧, 或者,從命令行使用下面的PHP代碼,看看我們?nèi)绾螠y(cè)試函數(shù)。<?phpfunctionarray_has_duplicates ($array) {

returncount($array)!==count(array_unique($array));

}$microtimes= array();

for($i=0;$i<1000;$i++) {$microtimes[] =get_clean_microtimestamp_string();

}

foreach($microtimesas$microtime) {

echo$microtime."n";

}

if(array_has_duplicates($microtimes)) {

echo"FOUND DUPLICATES!n";

}

else {

echo"NO DUPLICATES FOUND. AWESOME!n";

}

總結(jié)

以上是生活随笔為你收集整理的php日期转微秒,使用PHP生成独特的微秒级的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。