Convert java timestamp to php timestamp

coldplay.xixi
Release: 2023-03-02 10:26:01
Original
2600 people have browsed it

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.

Convert java timestamp to php timestamp

How to convert java timestamp to php timestamp:

1. Convert to string first

$utStr = $javaUt . '';
$utLen = strlen($utStr);
Copy after login

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;
   }
Copy after login

3. Intercept and convert it into an integer

return intval(substr($utStr, 0, $utLen - 3));
Copy after login

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 . &#39;&#39;;
        $utLen = strlen($utStr);
        // java的时间戳是13位 小于等于10位的直接返回
        if ($utLen <= 10) {
            return $javaUt;
        }
        // 截取并且转成整型
        return intval(substr($utStr, 0, $utLen - 3));
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template