Home  >  Article  >  Backend Development  >  What are the ways to get the current timestamp in php

What are the ways to get the current timestamp in php

青灯夜游
青灯夜游Original
2021-11-02 19:08:1526574browse

How to get the current timestamp in php: 1. Use the time() function directly, with the syntax "time()"; 2. Use the strtotime() function, with the syntax "strtotime("now")".

What are the ways to get the current timestamp in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php gets the current time Stamping method

1. Use time()

time() function returns the Unix epoch (January 1 1970 00:00:00 GMT) the current time in seconds.

Syntax: time();

Returns an integer containing the Unix timestamp of the current time.

Example:

<?php
echo time();
?>

Output:

1635851460

2. Use strtotime()

strtotime() function to Any string datetime description resolves to a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT).

语法:strtotime ( $time [, $now = time() ] )
  • time: required. Specifies a date/time string.

  • #now: Optional. Specifies the timestamp used to calculate the return value. If this parameter is omitted, the current time is used.

Example: Current timestamp

<?php
header("Content-type:text/html;charset=utf-8");
echo strtotime("now");
?>

Output:

1635851553

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the ways to get the current timestamp in php. 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