Home Backend Development PHP Problem How to convert the value obtained by time() into date string form in php

How to convert the value obtained by time() into date string form in php

Feb 15, 2022 pm 04:43 PM
date() php

In PHP, you can use the date() function to convert the value returned by time() into a date string format, with the syntax "date("Y-m-d H:i:s",time())". time() will return a timestamp representing the current time, while date() can format the timestamp and return a formatted date string.

How to convert the value obtained by time() into date string form in php

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

php will obtain time() Convert the value to string form

In php, you can use the date() function to convert the value returned by time() to string form.

<?php
header("Content-type:text/html;charset=utf-8");
ini_set(&#39;date.timezone&#39;, &#39;Asia/Shanghai&#39;);//设置时区
echo "当前是:".date("Y-m-d H:i:s",time());
?>
Copy after login

How to convert the value obtained by time() into date string form in php

Description: The

time() function returns the Unix epoch since January 1 1970 00:00:00 GMT The number of seconds of the current time.

date() function formats local date and time and returns the formatted date string. The syntax is as follows:

date(format,timestamp);
Copy after login
##ParameterDescription Optional. Specifies an integer Unix timestamp. The default is the current local time (time()).
format Required. Specifies the format of the output date string. The following characters are available:

    d - day of the month (from 01 to 31)
  • D - textual representation of the day of the week (in three letters)
  • j - Day of the month without leading zeros (1 to 31)
  • l (lowercase 'L') - Full textual representation of the day of the week
  • N - The day of the week in ISO-8601 numeric format (1 means Monday, 7 means Sunday)
  • S ​​- The English ordinal suffix of the day of the month ( 2 characters: st, nd, rd, or th. Used with j)
  • w - Numeric representation of the day of the week (0 for Sunday, 6 for Saturday)
  • z - Day of the year (from 0 to 365)
  • W - Day of the year in ISO-8601 number format (week starts on Monday)
  • F - Full textual representation of the month (January to December)
  • m - Numerical representation of the month (from 01 to 12)
  • M - short text representation of the month (in three letters)
  • n - numeric representation of the month without leading zeros (1 to 12)
  • t - the number contained in the given month Number of days
  • L - Whether it is a leap year (1 if it is a leap year, 0 otherwise)
  • o - Year number under the ISO-8601 standard
  • Y - Year number Four-digit representation of
  • y - Two-digit representation of year
  • a - Lowercase representation: am or pm
  • A - Uppercase representation: AM or PM
  • B - Swatch Internet Time (000 to 999)
  • g - 12 hour clock without leading zeros (1 to 12)
  • G - 24 hour clock without leading zeros Zeros (0 to 23)
  • h - 12-hour clock, with leading zeros (01 to 12)
  • H - 24-hour clock, with leading zeros (00 to 23)
  • i - Minutes, with leading zeros (00 to 59)
  • s - Seconds, with leading zeros (00 to 59)
  • u - Microseconds (new in PHP 5.2.2 )
  • e - Time zone identifier (e.g. UTC, GMT, Atlantic/Azores)
  • I (uppercase i) - Whether the date is in daylight saving time (if so then is 1, otherwise 0)
  • O - The difference in Greenwich Mean Time (GMT) in hours (Example: 0100)
  • P - The difference in Greenwich Mean Time (GMT) Difference, unit is hours:minutes (new in PHP 5.1.3)
  • T - abbreviation of time zone (examples: EST, MDT)
  • Z - time zone in seconds Offset. Negative time zone offsets west of UTC (-43200 to 50400)
  • c - ISO-8601 standard dates (e.g. 2013-05-05T16:34:42 00:00)
  • r - A date in RFC 2822 format (e.g. Fri, 12 Apr 2013 12:01:05 0200)
  • U - The number of seconds elapsed since the Unix epoch (January 1 1970 00:00:00 GMT)
Also, you can also use the following predefined constants (available starting from PHP 5.1.0):

    DATE_ATOM - Atom (for example: 2013-04-12T15:52:01 00:00)
  • DATE_COOKIE - HTTP Cookies (Example: Friday, 12-Apr-13 15:52:01 UTC)
  • DATE_ISO8601 - ISO-8601 (Example: 2013-04-12T15 :52:01 0000)
  • DATE_RFC822 - RFC 822 (Example: Friday, 12 Apr 13 15:52:01 0000)
  • DATE_RFC850 - RFC 850 (Example: Friday, 12-Apr- 13 15:52:01 UTC)
  • DATE_RFC1036 - RFC 1036 (Example: Fri, 12 Apr 13 15:52:01 0000)
  • DATE_RFC1123 - RFC 1123 (Example: Fri, 12 Apr 2013 15:52:01 0000)
  • DATE_RFC2822 - RFC 2822 (Fri, 12 Apr 2013 15:52:01 0000)
  • DATE_RFC3339 - Same as DATE_ATOM (as of PHP 5.1.3)
  • DATE_RSS - RSS (Fri, 12 Aug 2013 15:52:01 0000)
  • DATE_W3C - World Wide Web Consortium (Example: 2013-04-12T15:52:01 00:00)
timestamp
Recommended study: "

PHP Video Tutorial"

The above is the detailed content of How to convert the value obtained by time() into date string form in php. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles