Get Current Date and Time using Python Leave a comment

Get Present Date and Time utilizing Python.

In Python, date and time usually are not a knowledge kind of its personal, however a module named datetime might be imported to work with the date in addition to time. Datetime module comes constructed into Python, so there isn’t a want to put in it externally. To get each present date and time datetime.now() operate of datetime module is used. This operate returns the present native date and time.


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
# importing datetime module for now()
import datetime

# utilizing now() to get present time
current_time = datetime.datetime.now()

# Printing attributes of now().
print("The attributes of now() are : ")

print("12 months : ", finish="")
print(current_time.yr)

print("Month : ", finish="")
print(current_time.month)

print("Day : ", finish="")
print(current_time.day)

print("Hour : ", finish="")
print(current_time.hour)

print("Minute : ", finish="")
print(current_time.minute)

print("Second : ", finish="")
print(current_time.second)

print("Microsecond : ", finish="")
print(current_time.microsecond)

Leave a Reply

%d bloggers like this: