python> link> strftime () and strptime () behavior / code

Target environment


python 2.6.6 on CentOS 6.8

I used strftime () and strptime () in coding in the past, but I forget the contents because I have poor memory.

I found the following link.

http://docs.python.jp/2/library/datetime.html#strftime-strptime-behavior

Roughly speaking, d.strftime (fmt) works like time.strftime (fmt, d.timetuple ()) in the time module.

If you don't know the "x" that says "It works like x", you're done. Not a self-contained document.

Conversely, the datetime.strptime () class method creates a datetime object from a format string that corresponds to a date or time.

In my understanding (may be wrong)

--strftime (): Convert datetime type to specified format string --strptime (): Convert specified format string to datetime type

I implemented the code. Reference http://qiita.com/shibainurou/items/0b0f8b0233c45fc163cd

import datetime

today = datetime.datetime.today()
print today

wrk = today.strftime("%Y-%m-%d_%H:%M:%S")
print "strftime:", wrk

dt = datetime.datetime.strptime(wrk, "%Y-%m-%d_%H:%M:%S")
print "strptime:", dt

result


Success	time: 0 memory: 9168 signal:0
2016-10-05 01:30:12.561105
strftime: 2016-10-05_01:30:12
strptime: 2016-10-05 01:30:12

Recommended Posts

python> link> strftime () and strptime () behavior / code
[Code] Module and Python version output
Differences between Python, stftime and strptime
Installation of Visual studio code and installation of python
Python> link> 2D array initialization and assignment
MessagePack-Try to link Java and Python with RPC
Python datetime How to calculate dates and convert strings strftime, strptime [Definitive Edition]
python character code
Links and memos of Python character code strings
[Python] Algorithm-aware code
List of Python code to move and remember
[Python] Explain the difference between strftime and strptime in the datetime module with an example
Let's write python code that parses go code and generates go code
Indent behavior of json.dumps is different between python2 and python3
Implementing a generator using Python> link> yield and next ()> yield
[python] Compress and decompress
python> link> range () / xrange ()
Python and numpy tips
[Python] pip and wheel
Python iterators and generators
Python code acceleration approach
Rewrite Python2 code to Python3 (2to3)
Python default argument behavior
[python] behavior of argmax
Python packages and modules
Vue-Cli and Python integration
infomap python draw code
Before writing Python code
Ruby, Python and map
About Python3 character code
blender, python, sphere behavior
python input and output
Python and Ruby split
Python Requests status code
OpenCV basic code (python)
Python3, venv and Ansible
Python asyncio and ContextVar
python> Link> PyUserInput package |
Python module num2words Difference in behavior between English and Russian
Install python and Visual Studio Code on windows10 (April 2020 version)
Create code that outputs "A and pretending B" in python
The process of making Python code object-oriented and improving it
Specification generation and code generation in REST API development (Python edition)
PyArmor ~ Easy way to encrypt and deliver python source code ~