SoFunction
Updated on 2024-12-17

python datetime strptime usage details

The code for strptime usage in datetime in python is shown below:

import datetime
day20 = ('2020-01-01 0:0:0', '%Y-%m-%d %H:%M:%S')
nowdate = ()
dela = day20 - nowdate
day = 
hour = int( / 60 / 60)
minute = int(( - hour * 60 * 60) / 60)
second =  - hour * 60 * 60 - minute * 60
print('And by New Year's Day 2020:' + str(day) + 'Heaven' + str(hour) + 'Hours' + str(minute) + 'Points' + str(second) + 'Seconds')

Time-date formatting notation in python

%y Two-digit year indication (00-99)
%Y Four-digit year indication (000-9999)
%m Month (01-12)
%d Day of the month (0-31)
%H 24-hour clock hours (0-23)
%I 12-hour hours (01-12)
%M minutes (00=59)
%S seconds (00-59)
%a Local simplified weekly name
%A Local full week name
%b Local simplified name of the month
%B Local full month name
%c Local corresponding date and time representation
%j Day of the year (001-366)
%p Local. or . Equivalents of
%U Number of weeks in a year (00-53) Sunday is the start of the week
%w Week (0-6), Sunday is the start of the week
%W Number of weeks in a year (00-53) Monday is the start of the week
%x Local representation of the corresponding date
%X Local corresponding time representation
%Z Name of the current time zone

grammatical

  1. time.strftime(time format)
  2. (String, time format)
  3. Example.
  4.  (str,'%Y-%m-%d')
  5. ().strftime("%Y-%m-%d %H:%M:%S")

summarize

The above is a small introduction to the use of strptime in python datetime, I hope to help you, if you have any questions please leave me a message, I will reply to you in a timely manner. I also thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!