How To Get Current Date Time or Now In Python? – POFTUT

How To Get Current Date Time or Now In Python?

Date and time is important part of the applications development. We generally need to set, get and change some data time information to our records. In this tutorial we will examine the python date time now functions and use cases with examples. For more information about Python date time functions can be get from following tutorial.

Python Date Time Functions With Examples

Python Date Time Operations

Import datetime

In order to use datetime functionalities weshould import the module named datetime . We can import datetime module like below. Function

After importing datetime module we can use provided class and functions. The simplest and most basic way to get current date and time is using function. This resides inside datetime module which means we should use following code in order to get current date and time. Function Function

Convert Now To String

While using now() function returned data will be a datetime object. But in some situations we may need to convert date time into string to use string variable or print to the console. We can use str() functions which will convert current date time to string.

Convert Now To String

Convert Now To String

Print Now with GM Time

We can use gmtime() function which will print current GM time. GM time is the current time in Greenwich where the world time starts and ends. We should import time module in order to use gmtime() function.

Print Now with GM Time

Print Now with GM Time

Print Specific Part Of Current Time

In this part we will print only specific part of the current time. We will use specifiers in order to print only required part of the time. We assume we have get the current time into variable named now like below.

echo '

Print Current Second

We can print current second like below.

LEARN MORE  How To Install Python (Python2 and Python3) On Windows?

Print Current Minute

We can print current minute like below.

Print Current Hour

We can print current hour like below.

Print Current Day of Month

We can print current day of month like below.

Print Current Month

We can print current month like below.

Print Current Year

We can print current year like below.

2 Responses

  1. mari says:

    I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.

  1. 15/12/2018


    The information mentioned inside the report are several of the ideal out there.

Leave a Reply

Your email address will not be published. Required fields are marked *