What are the ways to get the current timestamp in php

青灯夜游
Release: 2023-03-13 16:54:01
Original
26575 people have browsed it

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();
?>
Copy after login

Output:

1635851460
Copy after login

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() ] )
Copy after login
  • 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");
?>
Copy after login

Output:

1635851553
Copy after login

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!

Related labels:
php
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