ITblog

cakephp3の日時のYMDフォーマットについて

2021年05月18日

cakephp3で、データベースから取得した日時などのオブジェクトのデータを画面に出力する場合に、YMD形式のフォーマットに変換するケースがありますが、yは大文字か小文字か、など微妙なところでよく分からなかったのでメモです。

例えば、以下のように使います。

$now = Time::parse('2014-10-31');
// '2014-10-31 00:00:00' と出力します。
$now->i18nFormat('yyyy-MM-dd HH:mm:ss');

cakephpで使われているYMDフォーマットについては、以下のページに詳しく解説がありました。

Formatting Dates and Times | ICU Documentation

上記のページから抜粋します。

SymbolMeaningPatternExample Output
Gera designatorGGG, or GGG
GGGG
GGGGG
AD
Anno Domini
A
yyearyy
y or yyyy
96
1996
Yyear of “Week of Year”Y1997
uextended yearu4601
Ucyclic year name, as in Chinese lunar calendarU甲子
rrelated Gregorian yearr1996
QquarterQ
QQ
QQQ
QQQQ
QQQQQ
2
02
Q2
2nd quarter
2
qstand-alone quarterq
qq
qqq
qqqq
qqqqq
2
02
Q2
2nd quarter
2
Mmonth in yearM
MM
MMM
MMMM
MMMMM
9
09
Sep
September
S
Lstand-alone month in yearL
LL
LLL
LLLL
LLLLL
9
09
Sep
September
S
wweek of yearw
ww
27
27
Wweek of monthW2
dday in monthd
dd
2
02
Dday of yearD189
Fday of week in monthF2 (2nd Wed in July)
gmodified julian dayg2451334
Eday of weekE, EE, or EEE
EEEE
EEEEE
EEEEEE
Tue
Tuesday
T
Tu
elocal day of week
example: if Monday is 1st day, Tuesday is 2nd )
e or ee
eee
eeee
eeeee
eeeeee
2
Tue
Tuesday
T
Tu
cstand-alone local day of weekc or cc
ccc
cccc
ccccc
cccccc
2
Tue
Tuesday
T
Tu
aam/pm markerapm
hhour in am/pm (1~12)h
hh
7
07
Hhour in day (0~23)H
HH
0
00
khour in day (1~24)k
kk
24
24
Khour in am/pm (0~11)K
KK
0
00
mminute in hourm
mm
4
04
ssecond in minutes
ss
5
05
Sfractional second – truncates (like other time fields)
to the count of letters when formatting. Appends
zeros if more than 3 letters specified. Truncates at
three significant digits when parsing.
S
SS
SSS
SSSS
2
23
235
2350
Amilliseconds in dayA61201235
zTime Zone: specific non-locationzzz, or zzz
zzzz
PDT
Pacific Daylight Time
ZTime Zone: ISO8601 basic hms? / RFC 822
Time Zone: long localized GMT (=OOOO)
TIme Zone: ISO8601 extended hms? (=XXXXX)
ZZZ, or ZZZ
ZZZZ
ZZZZZ
-0800
GMT-08:00
-08:00, -07:52:58, Z
OTime Zone: short localized GMT
Time Zone: long localized GMT (=ZZZZ)
O
OOOO
GMT-8
GMT-08:00
vTime Zone: generic non-location
(falls back first to VVVV)
v
vvvv
PT
Pacific Time or Los Angeles Time
VTime Zone: short time zone ID
Time Zone: long time zone ID
Time Zone: time zone exemplar city
Time Zone: generic location (falls back to OOOO)
V
VV
VVV
VVVV
uslax
America/Los_Angeles
Los Angeles
Los Angeles Time
XTime Zone: ISO8601 basic hm?, with Z for 0
Time Zone: ISO8601 basic hm, with Z
Time Zone: ISO8601 extended hm, with Z
Time Zone: ISO8601 basic hms?, with Z
Time Zone: ISO8601 extended hms?, with Z
X
XX
XXX
XXXX
XXXXX
-08, +0530, Z
-0800, Z
-08:00, Z
-0800, -075258, Z
-08:00, -07:52:58, Z
xTime Zone: ISO8601 basic hm?, without Z for 0
Time Zone: ISO8601 basic hm, without Z
Time Zone: ISO8601 extended hm, without Z
Time Zone: ISO8601 basic hms?, without Z
Time Zone: ISO8601 extended hms?, without Z
x
xx
xxx
xxxx
xxxxx
-08, +0530
-0800
-08:00
-0800, -075258
-08:00, -07:52:58
'escape for text'(nothing)
' 'two single quotes produce one' '

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です