Python 日期格式 DM d H:i:s TY

Ray*_*ger 2 python date

我有一个日期时间对象,

import time, datetime, pytz
current_unixtime                            = time.time()
current_date_milis_for_blibli               = int(round(current_unixtime * 1000))
current_datetime_object                     = datetime.datetime.fromtimestamp(current_unixtime, pytz.timezone('Asia/Jakarta'))
Run Code Online (Sandbox Code Playgroud)

我如何将其转换为:

 Mon May 16 14:07:15 WIB 2016 
Run Code Online (Sandbox Code Playgroud)

或 PHP 等价形式:

D M d H:i:s T Y
Run Code Online (Sandbox Code Playgroud)

我尝试的内容写在下面,如您所见,我似乎无法获取日和月的 3 个字符:

year    = current_datetime_object.year
month   = current_datetime_object.month
day     = current_datetime_object.day
hour    = current_datetime_object.hour
minute  = current_datetime_object.minute
second  = current_datetime_object.second
Run Code Online (Sandbox Code Playgroud)

tec*_*kuz 5

result = current_datetime_object.strftime("%a %b %d %H:%M:%S %Z %Y")\n
Run Code Online (Sandbox Code Playgroud)\n\n

您还可以通过更改括号中的值来指定输出。

\n\n

示例基于 datetime.datetime(2013, 9, 30, 7, 6, 5)。

\n\n
Code    Example    Meaning\n\n%a      Mon                          # Weekday as locale\xe2\x80\x99s abbreviated name.\n%A      Monday                       # Weekday as locale\xe2\x80\x99s full name.\n%w      1                            # Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.\n%d      30                           # Day of the month as a zero-padded decimal number.\n%-d     30                           # Day of the month as a decimal number. (Platform specific)\n%b      Sep                          # Month as locale\xe2\x80\x99s abbreviated name.\n%B      September                    # Month as locale\xe2\x80\x99s full name.\n%m      9                            # Month as a zero-padded decimal number.\n%-m     9                            # Month as a decimal number. (Platform specific)\n%y      13                           # Year without century as a zero-padded decimal number.\n%Y      2013                         # Year with century as a decimal number.\n%H      7                            # Hour (24-hour clock) as a zero-padded decimal number.\n%-H     7                            # Hour (24-hour clock) as a decimal number. (Platform specific)\n%I      7                            # Hour (12-hour clock) as a zero-padded decimal number.\n%-I     7                            # Hour (12-hour clock) as a decimal number. (Platform specific)\n%p      AM                           # Locale\xe2\x80\x99s equivalent of either AM or PM.\n%M      6                            # Minute as a zero-padded decimal number.\n%-M     6                            # Minute as a decimal number. (Platform specific)\n%S      5                            # Second as a zero-padded decimal number.\n%-S     5                            # Second as a decimal number. (Platform specific)\n%f      0                            # Microsecond as a decimal number, zero-padded on the left.\n%z                                   # UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).\n%Z                                   # Time zone name (empty string if the object is naive).\n%j      273                          # Day of the year as a zero-padded decimal number.\n%-j     273                          # Day of the year as a decimal number. (Platform specific)\n%U      39                           # Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.\n%W      39                           # Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.\n%c      Mon Sep 30 07:06:05 2013     # Locale\xe2\x80\x99s appropriate date and time representation.\n%x      09/30/13                     # Locale\xe2\x80\x99s appropriate date representation.\n%X      07:06:05                     # Locale\xe2\x80\x99s appropriate time representation.\n%%      %                            # A literal \'%\' character.\n
Run Code Online (Sandbox Code Playgroud)\n\n

示例取自此处

\n