search
Homephp教程php手册PHP获取当前日期和时间及格式化方法参数

PHP获取当前日期和时间及格式化方法参数

   这篇文章主要介绍了PHP获取当前日期和时间及格式化方法参数,本文先是讲解了获取当前日期时间的方法,其后总结了格式化参数,需要的朋友可以参考下

  使用函式 date() 实现

 代码如下:


 

  显示的格式: 年-月-日 小时:分钟:秒

  相关时间参数:

  a - "am" 或是 "pm"

  A - "AM" 或是 "PM"

  d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"

  D - 星期几,三个英文字母; 如: "Fri"

  F - 月份,英文全名; 如: "January"

  h - 12 小时制的小时; 如: "01" 至 "12"

  H - 24 小时制的小时; 如: "00" 至 "23"

  g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"

  G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"

  i - 分钟; 如: "00" 至 "59"

  j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"

  l - 星期几,英文全名; 如: "Friday"

  m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"

  n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"

  M - 月份,三个英文字母; 如: "Jan"

  s - 秒; 如: "00" 至 "59"

  S - 字尾加英文序数,二个英文字母; 如: "th","nd"

  t - 指定月份的天数; 如: "28" 至 "31"

  U - 总秒数

  w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)

  Y - 年,四位数字; 如: "1999"

  y - 年,二位数字; 如: "99"

  z - 一年中的第几天; 如: "0" 至 "365"

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

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.