2022年 11月 9日

python日期格式问题datetime

最近做爬虫碰到了一个时间参数,格式比较少见,

时间参数格式:Wed, 13 Jun 2018 07:39:31 GMT+0800 (中国标准时间)

我想输出这种格式的参数,怎么调呢?代码如下:

  1. import datetime
  2. GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT+0800 (中国标准时间)'
  3. print datetime.datetime.now().strftime(GMT_FORMAT)
  1. #输出结果:
  2. 'Wed Jun 13 15:37:16 2018'

符号:

%a 星期几的简写 Weekday name, abbr

%d 每月的第几天 Day of the month

%b 月份简写 Month name, abbr.

%Y 年份 Year number