Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fa708f

Browse files
author
Soumitra
committed
python different datetime formats
1 parent cbf9788 commit 6fa708f

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import time
2+
import datetime
3+
4+
print('Today: ', datetime.date.today())
5+
6+
print("Time in seconds since the epoch: %s" %time.time())
7+
print("Current date and time: ", datetime.datetime.now())
8+
print("Or Current date and time: ", datetime.datetime.now().strftime("%y-%m-%d-%H-%M"))
9+
10+
print("Full weekday name: ", datetime.date.today().strftime("%A"))
11+
print("Abbreviated weekday name: ", datetime.date.today().strftime("%a"))
12+
13+
print("Full month name: ", datetime.date.today().strftime("%B"))
14+
print("Abbreviated month name: ", datetime.date.today().strftime("%b"))
15+
16+
print("Appropriate date and time: ", datetime.date.today().strftime("%c"))
17+
18+
print("Day of the month as a decimal number: ", datetime.date.today().strftime("%d"))
19+
20+
print("Microsecond as a decimal number: ", datetime.date.today().strftime("%f"))
21+
22+
print("Hour (24-hour clock) as a decimal number: ", datetime.date.today().strftime("%H"))
23+
print("Hour (12-hour clock) as a decimal number: ", datetime.date.today().strftime("%I"))
24+
25+
print("Day of the year as a decimal number: ", datetime.date.today().strftime("%j"))
26+
27+
print("Month as a decimal number: ", datetime.date.today().strftime("%m"))
28+
29+
print("Minute as a decimal number: ", datetime.date.today().strftime("%M"))
30+
31+
print("Either AM or PM: ", datetime.date.today().strftime("%p"))
32+
33+
print("Second as a decimal number: ", datetime.date.today().strftime("%S"))
34+
35+
print("Week number of the year: ", datetime.date.today().strftime("%U"))
36+
37+
print("Weekday as a decimal number: ", datetime.date.today().strftime("%w"))
38+
39+
print("Week number of the year: ", datetime.date.today().strftime("%W"))
40+
41+
print("Appropriate date representation: ", datetime.date.today().strftime("%x"))
42+
print("Appropriate time representation: ", datetime.date.today().strftime("%X"))
43+
44+
print("Year without century as a decimal number: ", datetime.date.today().strftime("%y"))
45+
print("Year with century as a decimal number: ", datetime.date.today().strftime("%Y"))
46+
47+
print("UTC offset in the form ±HHMM[SS[.ffffff]]: ", datetime.date.today().strftime("%z"))
48+
print("Time zone name (empty string if the object is naive): ", datetime.date.today().strftime("%Z"))
49+
50+
print("A literal '%' character: ", datetime.date.today().strftime("%%"))
51+
52+
print("ISO 8601 year with century: ", datetime.date.today().strftime("%G"))
53+
54+
print("ISO 8601 weekday as a decimal number: ", datetime.date.today().strftime("%U"))
55+
56+
print("ISO 8601 week as a decimal number: ", datetime.date.today().strftime("%V"))
57+
58+
print("Combine directives to form date and time: ", datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S%z %p"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You can go through the tutorial https://roytuts.com/how-to-display-date-time-in-different-formats-in-python/

0 commit comments

Comments
 (0)