Code666 (代码贴、代码片段)
创建
最近
趋势
关于
[PHP] 格式化时间 →→→→→
进入此内容的聊天室
来自 , 2020-12-08, 写在 PHP, 查看 121 次.
URL
http://www.code666.cn/view/818de4d2
下载便签
或
查看源码
—
扩张便签
来填满整个浏览器
格式化时间
date
(
)
函数用于格式化时间,返回一个字符串。
语法:
string
date
(
string format
[
,
int timestamp
]
)
参数 format 表示时间格式化的方式,可能的方式如下:
格式化方式说明:
格式化方式 说明
Y
4
位数字年,y为
2
位数字,如
99
即
1999
年
m 数字月份,前面有前导
0
,如
01
。n 为无前导
0
数字月份
F 月份,完整的文本格式,例如 January 或者 March
M 三个字母缩写表示的月份,例如 Jan 或者 Mar
d 月份中的第几天,前面有前导
0
,如
03
。j 为无前导
0
的天数
w 星期中的第几天,以数字表示,
0
表示星期天
z 年份中的第几天,范围
0
-
366
W 年份中的第几周,如第
32
周
H
24
小时格式,有前导
0
,h为
12
小时格式
G
24
小时格式,无前导
0
,g为对应
12
小时格式
i 分钟格式,有前导
0
s 秒格式,有前导
0
A 大写上下午,如AM,a为小写
可选参数 timestamp 表示时间戳,默认为
time
(
)
,即当前时间戳。
我们可以通过
date
(
)
函数提供的丰富格式化来显示需要的时间日期,如下面的例子:
date
(
"Y-m-d"
,
time
(
)
)
;
//显示格式如 2008-12-01
date
(
"Y.m.d"
,
time
(
)
)
;
//显示格式如 2008.12.01
date
(
"M d Y"
,
time
(
)
)
;
//显示格式如 Dec 01 2008
date
(
"Y-m-d H:i"
,
time
(
)
)
;
//显示格式如 2008-12-01 12:01
提示
如果您输出的时间和实际时间差
8
个小时(假设您采用的北京时区)的话,请检查php
.
ini文件,做如下设置:
date
.
timezone
=
PRC
如需做其他时区的设置请参考:http
:
//www.php.net/manual/en/timezones.php
回复 "格式化时间"
这儿你可以回复上面这条便签
作者
你的名字是?
标题
给你的便签一个标题。
语言
你的便签是以
Plain Text
HTML5
CSS
JavaScript
PHP
Python
Ruby
Lua
Bash
Erlang
Go
C
C++
Diff-output
LaTeX
SQL
XML
-----------------
4CS
MOS 6502
MOS 6502 Kick Assembler
MOS 6502 TASM/64TASS
Motorola 68000 Devpac Assembler
ABAP
Actionscript
ActionScript3
Ada
AIMMS
ALGOL 68
Apache
AppleScript
Apt sources.list
ARM Assembler
x86 Assembler
asymptote
ASP
autoconf
Autohotkey
AutoIT
AviSynth
Awk
BASCOM AVR
Basic4GL
BBCode
Brainfuck
BibTeX
BlitzBasic
BNF (Backus-Naur form)
Boo
C (for LoadRunner)
C for Macs
C with WiAPI
CAD DCL (Dialog Control Language)
AutoCAD/IntelliCAD Lisp
CFDG
ColdFusion
ChaiScript
Chapel
CIL (Common Intermediate Language)
Clojure
CMake
COBOL
CoffeeScript
C++ with WinAPI
C#
Cuesheet
D
Dart
DCS
DCL
DCPU/16 Assembly
Delphi (Object Pascal)
DIV
DOS
dot
E
ECMAScript
Eiffel
Email (mbox/eml/RFC format)
Enerscript
Euphoria
EZT
Formula One
Falcon
fo
Fortran
FreeBasic
FreeSWITCH
F#
GAMBAS
GDB
Genero
Genie
GNU Gettext .po/.pot
glSlang
GML
Gnuplot script
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML 4.01 strict
Icon
Unoidl
INI
Inno Script
INTERCAL
Io
ISPF Panel
J
Java
Java 5
Job Control Language
jQuery 1.3
KLone with C
KLone with C++
Kotlin
Liberty BASIC
LDIF
Generic Lisp
LLVM
Locomotive Basic (Amstrad CPC series)
Logcat
Logtalk
LOLcode
@Formula/@Command
LotusScript
Lightwave Script
Linden Scripting
Motorola 68000 Assembler
MagikSF
Make
MapBasic
Matlab M-file
mIRC Scripting
MMIX Assembler
Modula-2
Modula-3
Microchip Assembler
MXML
MySQL
Nagios
NetRexx
newLISP
nginx
Nimrod
Nullsoft Scriptable Install System
Oberon-2
Objective-C
Objeck Programming Language
OCaml (Objective Caml)
GNU Octave M-file
OpenOffice.org Basic
ooRexx
Oracle 11i
Oracle 8
Delphi Prism (Oxygene)
Oz
ParaSail
PARI/GP
Pascal
PCRE
Per (forms)
Perl
Perl 6
OpenBSD packet filter
PIC16 Assembler
Pike
Pixel Bender 1.0
PL/I
Oracle 9.2 PL/SQL
PostgreSQL
Postscript
Povray
PowerBuilder (PowerScript)
PowerShell
ProFTPd
Progress
Prolog
Property
ProvideX
PureBasic
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
Racket
Ruby (with Ruby on Rails Framework)
RBS Script
Rebol
Microsoft Registry Editor
Rexx
robots.txt
RPM Spec
R
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty template
SPARK
SPARQL
StandardML
StoneScript
SystemVerilog IEEE 1800-2009(draft8)
TCL/iTCL
Tera Term Macro
thinBasic
T-SQL
TypoScript
Unicon
UnrealScript
UPC
Urbi
Vala
Visual Basic
VB.NET
VBScript
Vedit macro language
Verilog
VHDL
Vim scripting
Visual FoxPro
Visual Prolog
Whitespace
Whois response (RPSL format)
WinBatch
XBasic
xorg.conf
Axapta/Dynamics Ax X++
YAML
ZiLOG Z80 Assembler
ZXBasic
你的便签
在这儿输入便签内容
格式化时间 date() 函数用于格式化时间,返回一个字符串。 语法: string date( string format [, int timestamp] ) 参数 format 表示时间格式化的方式,可能的方式如下: 格式化方式说明: 格式化方式 说明 Y 4位数字年,y为2位数字,如99即1999年 m 数字月份,前面有前导0,如01。n 为无前导0数字月份 F 月份,完整的文本格式,例如 January 或者 March M 三个字母缩写表示的月份,例如 Jan 或者 Mar d 月份中的第几天,前面有前导0,如03。j 为无前导0的天数 w 星期中的第几天,以数字表示,0表示星期天 z 年份中的第几天,范围0-366 W 年份中的第几周,如第32周 H 24小时格式,有前导0,h为12小时格式 G 24小时格式,无前导0,g为对应12小时格式 i 分钟格式,有前导0 s 秒格式,有前导0 A 大写上下午,如AM,a为小写 可选参数 timestamp 表示时间戳,默认为 time() ,即当前时间戳。 我们可以通过 date() 函数提供的丰富格式化来显示需要的时间日期,如下面的例子: date("Y-m-d",time()); //显示格式如 2008-12-01 date("Y.m.d",time()); //显示格式如 2008.12.01 date("M d Y",time()); //显示格式如 Dec 01 2008 date("Y-m-d H:i",time()); //显示格式如 2008-12-01 12:01 提示 如果您输出的时间和实际时间差8个小时(假设您采用的北京时区)的话,请检查php.ini文件,做如下设置: date.timezone = PRC 如需做其他时区的设置请参考:http://www.php.net/manual/en/timezones.php
创建短链接
创建一个较短的URL,连接到这个便签
私人
私人便签不会显示在最近列表中
保存期限
我们应该什么时候删除这张便签?
阅后即焚
五分钟
一小时
一天
一周
一月
一年
永久保留
防滥用
键入这些字符
创建