How to convert java timestamp to php timestamp: first convert the java timestamp into a string, the code is [$utStr = $javaUt . '';]; then if the java timestamp is less than or equal to 10 digits, directly Return; finally intercept and convert it into an integer.
How to convert java timestamp to php timestamp:
1. Convert to string first
$utStr = $javaUt . ''; $utLen = strlen($utStr);
2. The timestamp of java is 13 digits. If it is less than or equal to 10 digits, it will be returned directly.
if ($utLen <= 10) { return $javaUt; }
3. Intercept and convert it into an integer
return intval(substr($utStr, 0, $utLen - 3));
The complete code is as follows:
/** * java时间戳转php时间戳 * @param int $javaUt java的时间戳 * @return int * @Date 2019/8/26 */ public static function javaUt2PhpUt($javaUt) { if (!($javaUt && $javaUt > 0)) { return $javaUt; } // 先转成字符串 $utStr = $javaUt . ''; $utLen = strlen($utStr); // java的时间戳是13位 小于等于10位的直接返回 if ($utLen <= 10) { return $javaUt; } // 截取并且转成整型 return intval(substr($utStr, 0, $utLen - 3)); }
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of Convert java timestamp to php timestamp. For more information, please follow other related articles on the PHP Chinese website!