Note: [Python3] Convert datetime to a string in any format you like

Use strftime ()

>>> from datetime import datetime
>>> datetime.now().strftime('%Y%m%d-%H%M%S')
'20191219-140750'

https://docs.python.org/ja/3/library/datetime.html#strftime-and-strptime-format-codes

ISO 8601 format

>>> datetime.now().isoformat()
'2019-12-19T14:11:53.346885'

Recommended Posts

Note: [Python3] Convert datetime to a string in any format you like
How to convert / restore a string with [] in python
How to import a file anywhere you like in Python
Timezone specification when converting a string to datetime type in python
How to embed a variable in a python string
Python Note: When assigning a value to a string
I made a script in python to convert .md files to Scrapbox format
Create a datetime object from a string in Python (Python 3.3)
What do you like about how to convert an array (list) to a string?
I want to embed a variable in a Python string
[Python] How to expand variables in a character string
Things to note when initializing a list in Python
Convert / return class object to JSON format in Python
[Python] Created a method to convert radix in 1 second
python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type
[python] Convert date to string
Python / datetime> Implementation to convert YYYYMMDD format to YYYY / MM / DD
Convert markdown to PDF in Python
6 ways to string objects in Python
Convert a string to an image
Create a random string in Python
Convert to a string while outputting standard output with Python subprocess
Determine the date and time format in Python and convert to Unixtime
A note on what you did to use Flycheck with Python
How to make a string into an array or an array into a string in Python
[Introduction to Python] How to output a character string in a Print statement
How to get a string from a command line argument in python
If you want to assign csv export to a variable in python
Check if you can connect to a TCP port in Python
When you want to replace multiple characters in a string without using regular expressions in python3 series
Conversion of string <-> date (date, datetime) in Python
[Python] How to convert a 2D list to a 1D list
Convert psd file to png in Python
[Python] How to invert a character string
How to get a stacktrace in python
Convert Python date types to RFC822 format
Generate a class from a string in Python
How to convert DateTimeField format in Django
Convert from Markdown to HTML in Python
Download files in any format using Python
Convert absolute URLs to relative URLs in Python
I wrote a code to convert quaternions to z-y-x Euler angles in Python
Convert XML document stored in XML database (BaseX) to CSV format (using Python)
Mayungo's Python Learning Episode 6: I tried to convert a character string to a number
[Python] How to put any number of standard inputs in a list
I want to convert a table converted to PDF in Python back to CSV
I want to batch convert the result of "string" .split () in Python
I want to color a part of an Excel string in Python
How to write a string when there are multiple lines in python
[Introduction to Python] How to write a character string with the format function
How to format a list of dictionaries (or instances) well in Python
Get a datetime instance at any time of the day in Python
A note I looked up to make a command line tool in Python
Convert Unicode escape sequences like \ u in Python
Python string format
3 ways to parse time strings in python [Note]
Convert FBX files to ASCII <-> BINARY in Python
Try to calculate a statistical problem in Python
How to clear tuples in a list (Python)
Convert "number" of excel date to python datetime
A note to load open data in CSV format into Cloudant on Bluemix