如果我这样做:
echo microtime(true);
我得到以下结果:
- 在我的本地 Windows 开发环境中,我获得了 4 位精度(例如 1310564569.4162)。
- 在我的实时 CentOS (Linux) 服务器上,我得到了 2 位数的精度(例如 1310564569.41)。
好吧,根据你运行的平台,你会得到不同的精度?或者这是一个 PHP/OS 配置?
同样来自 microtime PHP 文档:
This function is only available on operating systems that support the gettimeofday() system call.
哪些操作系统(或条件/配置)不支持此功能?
最佳答案
If you pass true to microtime() as its only parameter, PHP will return the time in a more obvious format - seconds.microseconds, like this: 1174676587.5996
When using microtime(), keep in mind that the return value is a floating-point number. There is a setting in your php.ini file called "precision", which sets the number of significant digits to show in floating-point numbers - note that is significant digits, not decimal places, which means your return value from microtime() may not be as precise as you want. Above, for example, you can see we only have four decimal places returned - this is because php.ini defaults precision to 14, and there are ten digits before the decimal place.
If you increase the value of precision up to, say, 18, and run microtime() again, you will get results that are more accurate: 1174677004.8997819.
关于php - PHP 在不同操作系统下的微秒精度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6680053/