search
Homephp教程php手册PHP中Date()时间日期函数的使用方法小结

PHP开发中Date()时间日期函数的使用方法php date() 函数可把时间戳格式化为可读性更好的日期和时间。

语法

date(format,timestamp)参数 描述
format 必需。规定时间戳的格式。
timestamp 可选。规定时间戳。默认是当前的日期和时间

要找出前一天的时间就是 time()-60*60*24;
要找出前一年的时间就是 time()*60*60*24*365
那么如何把这个数字换成日期格式呢 ,就要用到date()函数了
$t=time();www.3ppt.com
echo date("y-m-d h:i:s" ,$t);

每一个参数的格式分别表示:
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"
其它不在上列的字符则直接列出该字符

php 日期 - 格式化日期

date() 函数的第一个参数规定了如何格式化日期/时间。它使用字母来表示日期和时间的格式。这里列出了一些可用的字母:
d - 月中的天 (01-31)
m - 当前月,以数字计 (01-12)
y - 当前的年(四位数)
您可以在我们的 php date 参考手册中,找到格式参数中可以使用的所有字母。
可以在字母之间插入其他字符,比如 "/"、"." 或者 "-",这样就可以增加附加格式了:

代码如下:

<?php 
echo date("y/m/d"); 
echo "<br />"; 
echo date("y.m.d"); 
echo "<br />"; 
echo date("y-m-d"); 
?>

更多相关教程请访问 php编程从入门到精通全套视频教程

Statement
This article is reproduced at:脚本之家. If there is any infringement, please contact admin@php.cn delete

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 Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

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.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use