0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

日付のフォーマット

Posted at

python

from datetime import datetime
now =datetime.now()
now_hms = "{0:%H:%M:%S}".format(now)
print(now_hms)
結果 '07:04:27'
from datetime import datetime
now_timestamp=str(datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
print(now_timestamp)
結果 '2019_07_03_07_04_31'

PHP

$date = '2015-12-31';
echo date('Y年m月d日',  strtotime($date));
結果 '2015年12月31日'

SQL文

date="2015-05-01"
DATE_FORMAT(date,"%Y-%m")
結果 '2018-05'

【日付フォーマット 共通】

phpでは'%'はつけない

文字 説明
%Y 年(西暦4桁) 2015
%y 年(西暦2桁) 15
%m 月(ゼロ埋め) 01~12
%c 月(ゼロ無し) 1~12
%M 月(英字) January~December
%b 月(省略英字) Jan~Dec
%d 日(ゼロ埋め) 01~31
%e 日(ゼロ無し) 1~31
%I 時(12時間/ゼロ無) 1~12
%k 時(24時間/ゼロ無) 0~23
%h 時(12時間/ゼロ有) 01~12
%H 時(24時間/ゼロ有) 00~23
%i 分(ゼロあり) 00~59
%s 秒(ゼロあり) 00~59
%f マイクロ秒 000000
%M 曜日(英字) Sunday~Saturday
%a 曜日(省略英字) Sun~Sat
%w 曜日(数字) 0(日曜)~6(土曜)
%j 年間の通算日数 0~365
%p 午前/午後 AM/PM
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?