8000 Formatting time output · neryuuk/learning-python@b5017f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5017f7

Browse files
committed
Formatting time output
1 parent 0531f18 commit b5017f7

File tree

2 files changed

+11
-46
lines changed

2 files changed

+11
-46
lines changed

Ch4 - Dates and Times/formatting_finished.py

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
#
2-
# Example file for formatting time and date output
3-
# LinkedIn Learning Python course by Joe Marini
4-
#
5-
6-
71
from datetime import datetime
82

3+
94
def main():
105
# Times and dates can be formatted using a set of predefined string
11-
# control codes
6+
# control codes
7+
now = datetime.now()
128

13-
149
#### Date Formatting ####
15-
1610
# %y/%Y - Year, %a/%A - weekday, %b/%B - month, %d - day of month
17-
11+
print(now.strftime("The current year is %Y"))
12+
print(now.strftime("%a, %d %B, %y"))
1813

1914
# %c - locale's date and time, %x - locale's date, %X - locale's time
20-
15+
print(now.strftime("Locale date and time %c"))
16+
print(now.strftime("Locale date %x"))
17+
print(now.strftime("Locale date %X"))
2118

2219
#### Time Formatting ####
23-
2420
# %I/%H - 12/24 Hour, %M - minute, %S - second, %p - locale's AM/PM
25-
21+
print(now.strftime("Current time is %I:%M:%S %p"))
22+
print(now.strftime("Current time is %H:%M:%S"))
23+
2624

2725
if __name__ == "__main__":
2826
main()

0 commit comments

Comments
 (0)
0