Skip to content

Update Date_Time_Timestamp.py #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Date Time Timestamp/Date_Time_Timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
# get day of the week using date.weekday() # Monday is 0

from datetime import date
d1 = date.today()
print(d1)
print(d1.month, d1.day, d1.year)
print(d1.weekday())
todays_date = date.today()
print(todays_date)
print(todays_date.month, todays_date.day, todays_date.year)
print(todays_date.weekday())

# ISO format is a string format, yyyy-mm-dd
# ---------------------------
# date_object.isoformat() does the same thing as str(date_object)

from datetime import date
d1 = date.fromisoformat('2011-11-23')
print(d1)
print(str(d1))
print(d1.isoformat())
d1
todays_date = date.fromisoformat('2011-11-23')
print(todays_date)
print(str(todays_date))
print(todays_date.isoformat())
todays_date

# Comparison, addition and sutraction of dates
# ---------------------------
Expand All @@ -42,10 +42,10 @@
# The same comparison and add/subtract operations can be used with time objects.

from datetime import date
d1 = date.today()
todays_date = date.today()
d2 = date(2015, 5, 14)
print(d1 > d2)
print(d1 - d2)
print(todays_date > d2)
print(todays_date - d2)

# Time
# ---------------------------
Expand Down Expand Up @@ -95,9 +95,9 @@
# A timedelta can also be multiplied or divided by an integer or float

from datetime import timedelta, date, time
d1 = date(2011, 6, 15)
todays_date = date(2011, 6, 15)
d2 = date(2012, 9, 18)
td = d2 - d1
td = d2 - todays_date
print(td, type(td))
print(td.total_seconds())
print(td * 3)
Expand Down Expand Up @@ -130,4 +130,4 @@
start_time = time.process_time()
# do some stuff
end_time = time.process_time()
print('operation executed in ', end_time - start_time)
print('operation executed in ', end_time - start_time)