PHP timestamps and how to convert between dates
The conversion between timestamp and date in PHP is realized through the data() function and strtotime() function. The data function realizes the conversion of timestamp to date, and the strtotime function realizes the conversion of date to timestamp.
Time stamp to date date()
time()
<?php var_dump(time()); //获取当前时间戳 int(1502245603)
date(format ,timestamp)
format Required. Specifies the format of the timestamp.
timestamp is optional. Specify timestamp. The default is the current time and date
To convert timestamp to date, you can use date('Y-m-s h:i:s', specific timestamp to achieve).
Y : Year (four digits) uppercase
m: month (two digits, add 0 if the first digit is missing) lowercase
d: day (two digits, add 0 if the first digit is missing) lowercase
H: Hour 24-hour hour format with leading zero
h: hour 12-hour hour format with leading zero
i : minute with leading zero
s: seconds with leading zero (00-59)
a: Lowercase noon and afternoon (am or pm)
The distinction between upper and lower case is very important, such as the following example:
var_dump(date('Y-m-d H:i:s', 1502204401)); //H 24小时制 2017-08-08 23:00:01 var_dump(date('Y-m-d h:i:s', 1502204401)); //h 12小时制 2017-08-08 11:00:01
Date to timestamp strtotime()
strotime is a very flexible and smart function that can recognize Chinese, English, and numbers. Let’s experience it
<?php echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n"; echo strtotime("20170808 23:00:01"), "\n"; ?>
Related recommendations:
How to get the year, month and day in php Timestamp and date methods
Share the method of outputting time by date() function in PHP
The above is the detailed content of PHP timestamps and how to convert between dates. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Golang time conversion: Tips for converting dates and times to each other. As the Go language continues to develop in various fields, the need to process dates and times is becoming more and more common. In the Go language, date and time conversion is a basic operation and a common requirement in development. This article will introduce how to convert date and time in Golang, and provide specific code examples to help developers better master this technique. Representation of date and time In Go language, date and time are represented by time.Time respectively.

PHP is a server-side scripting language widely used in website development. Its flexibility and powerful functions allow developers to quickly implement various functions. In website development, we often encounter the need to convert the time in different countries or regions, such as converting American time to Chinese time. This article will introduce how to use PHP to quickly convert American time to Chinese time, and provide specific code examples. First, we need to clarify the time zone difference between US time and China time. The United States mainly has multiple time zones, including the Eastern

The content of the article is as follows: Title: Detailed explanation of how to use the time conversion function in DedeCMS. In DedeCMS, time conversion is a common and commonly used function. It can help website developers flexibly process time data and implement operations such as time formatting, time zone conversion, and conversion between timestamps and dates. In this article, we will introduce in detail how to use the time conversion function in DedeCMS and provide specific code examples. 1. For time formatting in DedeCMS, you can use GetDateMK

MySql is a commonly used relational database management system that supports data storage and operations of multiple date and time types. This article will introduce how to process and convert date and time data in MySql. 1. Date and time types MySql supports multiple date and time types, including DATE, TIME, DATETIME, TIMESTAMP, etc. The specific definitions of these types are as follows: DATE: represents date in the format of 'YYYY-MM-DD'. The valid range is '1000-01-

Title: PHP Programming Tips: Converting American Time to Chinese Time In cross-time zone application development, we often encounter situations where we need to convert times in different time zones. This article will introduce how to use PHP programming to convert American time to Chinese time, and provide specific code examples. First, we need to understand the time difference between US time and China time. The difference between US Eastern Time and China Time is 12 hours, that is, US time is 12 hours behind China time. Therefore, we need to add 12 hours to US time to

PHP is a commonly used server-side scripting language used for website development and dynamic web page generation. During the development process, we often encounter situations where we need to convert times in different time zones, such as converting American time to Chinese time. Next, we will introduce some PHP methods to convert American time to Chinese time, and attach specific code examples. Use the DateTime class and DateTimeZone class for conversion: $usDateTime=newDateTime('2023

Time conversion is a common requirement in website development, especially in CMS systems like dedecms. In order to handle the display and conversion of time more conveniently, you can use some time conversion plug-ins. This article will recommend a time conversion plug-in and provide specific usage tips and code examples. Recommended time conversion plug-in: Moment.jsMoment.js is a powerful time processing library that can help developers easily parse, verify, operate and format dates and times in JavaScript.

Golang time conversion: Detailed explanation of time formatting operation In the Go language, time processing is a common requirement, and time formatting operation is an important part of it. This article will introduce time conversion and formatting operations in Golang, including time parsing, formatting, time zone conversion, etc., and use specific code examples to help readers better understand. 1. Time analysis In the Go language, the time format has certain specifications, the most common one is the RFC3339 specification. Here is a sample code for time parsing: pa
