Python Date Object
Rushikesh J.
Software Test Engineer @Vinz Global | Robot Framework | Manual Testing, Automation Testing | Python | Selenium | GIT | JIRA | Immediate Joiner | API Testing Using Postman | Jenkins
We can work with time and date with Python. There are two module in Python time and datetime that used to work with time and date.
Time module:
Time module have following classes to work with date and time having different methods and properties.
i.time()? : It return time in seconds since epoch (Jan 1, 1970, 00:00:00)
ii.ctime() : It return current time. It can take seconds since epoch as argument.
iii.sleep()? : it suspends execution of code according to given seconds as argument.
iv.localtime() : it used to convert seconds into date and time. It return struct_time object. using strcut_time object, we can get date and time
datetime module:
Following classes used in datetime module to work with date and time.
1) date Class :? Pass y, m, d argument to date class and we can also used today() method to print today date.
Attributes of date class
year
month
day
2) time Class :? It take h, m, s, ms as argument to print time.
Attributes of time class
hour
minute
second
microsecond
min
领英推荐
max
3) timedelta Class
This class is used to find difference between two dates and manipulation on date and time.
4) datetime Class : It have methods, attributes to work with date and time like now() method to return current date and time.
Attributes of datetime class
year
month
day
hour
minute
second
microsecond
List of Different problems related to Date and Time
USE of date and time to create application