Python Date Object

Python Date Object

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

  • Python program to display different Date Time formats
  • Python program to display current date and time
  • Python program to get current time in milliseconds
  • Python program to determine whether, specific year is leap year or not
  • Python program to Find Age of anyone, and also convert it into years, month, days, hours, minutes, seconds etc.
  • Python program to Find number of days between two days
  • Python program to Display yesterday, today or tomorrow
  • Python program to display previous 10 days starting from today
  • Python program to subtract 10 seconds from the current time.
  • Python program to display week number for specific date
  • Python program to select all the Mondays from a specified year


USE of date and time to create application

  1. Age calculator
  2. Countdown Time
  3. Alarm application
  4. Reminder application
  5. Display current date and time on invoices
  6. User should not be able to select admission date before today date



要查看或添加评论,请登录

社区洞察

其他会员也浏览了