0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonで、日時と時間、秒単位を表すには

Last updated at Posted at 2020-09-25

Pythonで学習したこと

Python認定技術者に向けて勉強しています。
実際にコードがどのように役立つかについてですが、
使う人の側にたったコードを試したいです。

実践したコード


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) //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')

エラーが出たコード

該当するソースコード

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

print(now-d)

今後の課題とします。

また、textを生成するコードも載せます。

0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?