I am using an API, and the API needs this data format:
Wed Jan 07 2015 18:58:40
How I can convert the time now to this data format, using the datetime
and time
modules?
I am using an API, and the API needs this data format:
Wed Jan 07 2015 18:58:40
How I can convert the time now to this data format, using the datetime
and time
modules?
print(datetime.now().strftime('%a %b %d %Y %H:%M:%S'))
Would display something like:
Thu Mar 24 2016 10:09:18
The formatting options used are as follows:
%a
Weekday as locale’s abbreviated name.%b
Month as locale’s abbreviated name.%d
Day of the month as a zero-padded decimal number.%Y
Year with century as a decimal number.%H
Hour (24-hour clock) as a zero-padded decimal number.%M
Minute as a zero-padded decimal number.%S
Second as a zero-padded decimal number.To then convert this to a format for sending, you probably want to investigate quote_plus()
, for example:
from datetime import datetime
import urllib
now = datetime.now().strftime('%a %b %d %Y %H:%M:%S')
print(urllib.parse.quote_plus(now))
This would give you:
Thu+Mar+24+2016+10%3A32%3A51