To represent date, time, time, and seconds in Python

What I learned in Python

I am studying for a Python certified technician. As for how the code actually helps, I want to try the code only on the side of the user.

Code practiced


import datetime

now = datetime.datetime.now()
print(now)
print(now.isoformat())
print(now.strftime('%d/%m/%y-%H%M%S%f'))

today = datetime.date.today()
print(today.isoformat('%d/%m/%y'))

t = datetime.time(hour=1, minute=0,second=5,microsecond=100)
print(t)
print(t.isoformat())
print(t.strftime('%H%_M_%S_%f'))

print(now)
d = datetime.timedelete(weeks=1)
#d = datetime.timedelete(days=1)
#d = datetime.timedelete(hours=1)
#d = datetime.timedelete(minutes=1)
#d = datetime.timedelete(second=1)
#d = datetime.timedelete(microsecond=1) //Select one argument
print(now-d)

import time
#pair print('###')
#time.sleep(10)
#pair print('###')
 import os
 import shutil

 file_name = 'test.txt'

 if os.path.exists(file_name):
     shutil.copy(file_name, "{}.{}".format(
     file_name, now.strftime('%Y_%m_%d_%H__%M_%S')))

with open(file_name, 'w') as f:
    f.write('test')

Code with the error

Applicable source code

print(now)
d = datetime.timedelete(weeks=1)

print(now-d)

This is a future issue.

Also, put the code to generate the text.

Recommended Posts

To represent date, time, time, and seconds in Python
Convert timezoned date and time to Unixtime in Python2.7
How to get the date and time difference in seconds with python
Determine the date and time format in Python and convert to Unixtime
How to stop a program in python until a specific date and time
Script to count and stop up to 5 seconds in Python in Blender
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)
Get the current date and time in Python, considering the time difference
Get date and time in specified format
Just print Python elapsed time in seconds
How to use is and == in Python
3 ways to parse time strings in python [Note]
How to generate permutations in Python and C ++
Date manipulation in Python
A clever way to time processing in Python
Send messages to Skype and Chatwork in Python
Date calculation in python
Date calculation in Python
How to plot autocorrelation and partial autocorrelation in python
Introduction to Time Series Analysis ~ Seasonal Adjustment Model ~ Implemented in R and Python
Extract "current date only" and "current date and time" with python datetime.
How to measure processing time in Python or Java
Convert date timezone (time difference) in Python (from string)
Write tests in Python to profile and check coverage
[Python] How to sort dict in list and instance in list
Multi-digit multiplication time up to 300 million digits in python
Summary of date processing in Python (datetime and dateutil)
[python] Convert date to string
To flush stdout in Python
Login to website in Python
Date and time ⇔ character string
Speech to speech in python [text to speech]
Unittest and CI in Python
String date manipulation in Python
How to develop in Python
Sort by date in python
Post to Slack in Python
[Python] Convert time display (str type) using "" "and"'" to seconds (float type) with datetime and timedelta
[Introduction to element decomposition] Let's arrange time series analysis methods in R and python ♬
[Python] Rename all image files in a specific folder by shooting date and time
Try to make it using GUI and PyQt in Python
How to swap elements in an array in Python, and how to reverse an array.
Application to display and search local memos (diary) in Python
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
How to generate exponential pulse time series data in python
Display numbers and letters assigned to variables in python print
Tips for coding short and easy to read in Python
A standard way to develop and distribute packages in Python
I tried to illustrate the time and time in C language
Useful tricks related to list and for statements in Python
Comparison of how to use higher-order functions in Python 2 and 3
[Python] Strengths and weaknesses of DataFrame in terms of time required
Introduction to Effectiveness Verification Chapters 4 and 5 are written in Python
Object-oriented in C: Refactored "○ ✕ game" and ported it to Python
How to execute external shell scripts and commands in python
Just try to receive a webhook in ngrok and python
How to log in to AtCoder with Python and submit automatically
An easy way to view the time taken in Python and a smarter way to improve it
[Python] How to do PCA in Python
Difference between list () and [] in Python
Difference between == and is in python