-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatting
31 lines (22 loc) · 845 Bytes
/
formatting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# Example file for formatting time and date output
#
from datetime import datetime
def main():
# Times and dates can be formatted using a set of predefined string
# control code
now = datetime.now()
#### Date formatting ####
# %y/%Y - year, %a/%A - weekday, %b/%B - month, %d - day of month
print(now.strftime("The current year is: %y"))
print(now.strftime("%a, %d %B, %y"))
#%c - locales'date and time, %x - locale's date, %x - locale's time
print(now.strftime("Locale date and time: %c"))
print(now.strftime("Locale date: %x"))
print(now.strftime("Locale time: %X"))
#### Time formatting ####
# %I/%H - 12/24 Hour, %M - minute, %S - second, %p - locale's AM/PM
print(now.strftime("Current time: %I:%M:%S %p"))
print(now.strftime("24-hour time: %H:%M"))
if __name__ == "__main__":
main()