codescracker


python

Python Date and Time



« Previous Tutorial Next Tutorial »


You are free to handle date and time in python. The time.time() function returns the current system time in ticks since 12:00 am, January 1, 1970. As you know time intervals are a floating-point number in units of seconds.

Python Date and Time Example

Here is an example using time.time() function in python:

# Python Date and Time - Example Program

import time;    # to include time module in this program

ticks = time.time()

print("Number of ticks since 12:00am, January 1970 is ", ticks);

Here is the sample output of the above Python program:

python date time

Here is another example program, prints the current date and time in python:

# Python Date and Time - Example Program

import time;

localtime = time.asctime(time.localtime(time.time()))

print("The current time = ", localtime);

Here is the sample output of the above program in python:

python print current date time

Here is one more example program in python, prints a calendar for a given month and year. For example, (2015, 2):

# Python Date and Time - Example Program

import calendar

calend = calendar.month(2015, 2)

print(calend)

Here is the sample output produced by the above python program:

python print calendar time date

More Examples

Here are two more examples uses date and time in python:


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test