Differences between Python, stftime and strptime

A memo about the difference between strftime and strptime

(1) Premise

Import the datetiem class of the datetime module and assign the result of the today () function to the variable t

from datetime import datetime
t = datetime.today
t

Then

datetime.datetime(2020, 3, 12, 23, 37, 45, 238787)

Becomes

(2) datetime type → str type

str_t = t.strftime('%Y year%m month%d day/%H o'clock%M minutes%S seconds')
str_t

Then

'March 12, 2020/23:37:45'

Becomes

(3) str type → datetime type

time_t = datetime.strptime(str_t, '%Y year%m month%d day/%H o'clock%M minutes%S seconds')
time_t

Then

datetime.datetime(2020, 3, 12, 23, 37, 45)

Will be.

Recommended Posts

Differences between Python, stftime and strptime
Differences in authenticity between Python and JavaScript
Differences between Ruby and Python in scope
Differences in syntax between Python and Java
Differences in multithreading between Python and Jython
Differences between Ruby and Python (basic syntax)
Summary of the differences between PHP and Python
Difference between Ruby and Python split
Differences between Windows and Linux directories
Difference between java and python (memo)
Difference between list () and [] in Python
Differences between yum commands and APT commands
Difference between == and is in python
Differences between symbolic links and hard links
Cooperation between python module and API
Difference between python2 series and python3 series dict.keys ()
I tried to enumerate the differences between java and python
[Python] Difference between function and method
Python --Difference between exec and eval
[Python] Difference between randrange () and randint ()
Differences between Python, read (), readline (), readlines ()
[Python] Difference between sorted and sorted (Colaboratory)
Summary of differences between Python and PHP (comparison table of main items)
Communicate between Elixir and Python with gRPC
difference between statements (statements) and expressions (expressions) in Python
python> link> strftime () and strptime () behavior / code
Difference between PHP and Python finally and exit
Difference between @classmethod and @staticmethod in Python
[Basic grammar] Differences between Ruby / Python / PHP
[Python] Difference between class method and static method
[Python3] Switch between Shift_JIS, UTF-8 and ASCII
[Python Iroha] Difference between List and Tuple
[python] Difference between rand and randn output
Matplotlib Basics / Differences between fig and axes
Differences between Numpy 1D array [x] and 2D array [x, 1]
Differences between Django's request.POST ['hoge'] and request.POST.get ('hoge')
Correspondence between Python built-in functions and Rust
Exchange encrypted data between Python and C #
Differences between queryStringParameters and multiValueQueryStringParameters in AWS Lambda
The answer of "1/2" is different between python2 and 3
[python] Difference between variables and self. Variables in class
[Python] Conversion memo between time data and numerical data
About the difference between "==" and "is" in python
Adjust font differences between Qt for Python OS
Python hand play (interoperability between CSV and PostgreSQL)
Differences and commonalities between dict, list, and tuple types
Differences between glibc, musl libc and go resolvers
Differences in string processing between Python, Ruby, JS, PHP (combination and variable expansion)
[python] Compress and decompress
Python and numpy tips
[Python] pip and wheel
Batch design and python
Differences in behavior between append () and "+ =" operators when adding data to a list in Python
Python packages and modules
Vue-Cli and Python integration
File write speed comparison experiment between python 2.7.9 and pypy 2.5.0
Between parametric and nonparametric
[Ruby vs Python] Benchmark comparison between Rails and Flask
Control other programs from Python (communication between Python and exe)
Difference between Ruby and Python in terms of variables
Ruby, Python and map