Home >Backend Development >PHP Problem >How to convert php 13-digit timestamp

How to convert php 13-digit timestamp

藏色散人
藏色散人Original
2020-08-26 09:54:075652browse

In PHP, the 13-digit timestamp can be converted through the "microtime" function. The syntax is "microtime(get_as_float);", the parameter "get_as_float" is optional, and the return value is "microsec sec".

How to convert php 13-digit timestamp

Recommended: "PHP Video Tutorial"

Convert 13-digit timestamp to 10-digit time Stamp

When we design the database, when the timestamp is stored in the database, under normal circumstances, I will design the storage type int with a length of 11,

In general, the timestamp is passed from the front end The length is a 10-digit timestamp, and the same is true for the php time() function. But if you

are docking with hardware, etc., if you forget to communicate. It is possible that the time passed is a 13-digit timestamp accurate to milliseconds. If stored directly in the database, the timestamp will be wrong! So if you let the hardware handle it, it's okay if it's the same company, but if it's docking, it's very troublesome. I encountered this problem today. I searched online and couldn't find a suitable method. I just wrote a function myself! Later I learned that in fact, PHP has its own function that can directly solve the problem

microtime(); you don’t need to write the function yourself if you use it

microtime() function returns the microsecond of the current Unix timestamp number.

Syntax

microtime(get_as_float);

Parameters

get_as_float Optional. When set to TRUE, specifies that the function should return a floating point number, otherwise a string. Default is FALSE.

Technical details

Return value: Default returns the string "microsec sec", where sec is the number of seconds since the Unix epoch (0:00:00 January 1, 1970 GMT), microsec is the microsecond part. If the get_as_float parameter is set to TRUE, returns a floating point number representing the current time in seconds since the Unix epoch, accurate to microseconds.

The above is the detailed content of How to convert php 13-digit timestamp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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