There are various ways Python supplies date and time feature to add in program. Python’s Time and calendar module helps in tracking date and time. Also the ‘datetime’ provide classes for controlling date and time by both simple and complex ways.
There are two different date and time objects. These are:
The differences between ‘naive’ and ‘aware’ objects are:
Defining Tick
As we all can make an idea that time intervals have to be represented in floating point number. The floating-point numbers in units of seconds are signified by Tick in python. Particular instants of time are represented in seconds since 12:00 am, 1st of January, of the year 1990. A popular module name ‘time’ is available which provides functions that let’s programmer work with time and made conversion between time-representation possible.
The pre-defined function time.time() is used to return the current time of the system.
The daytime module exports the constants listed below:
Two programs are shown showing the use of two different modules:
Example:
#!/usr/bin/python
import time;
ticktock = time.time();
print("Number of ticks:", ticktock)
Output:
Number of ticks: 1465927104.951356
Another program showing datetime module:
Example:
#!/usr/bin/python
from datetime import datetime
presentime = datetime.now()
print(" NOW THE TIME IS:", presentime)
print("Todays Date is:", presentime.strftime('%Y-%m-%d') )
print("Year is:", presentime.year)
print("MOnth is:", presentime.month)
print("Day is:", presentime.day)
0 Comments
If you have any doubts,please let me know