Develop your own virtual assistant using python - part 2
This is the part-2 of virtual assistant in python. Click the link for part -1 of virtual assistant program in python.
Now in this article, we will move forward and discuss more modules that we are going to use in our virtual assistant in python.
So let's start off,
🗓Datetime module in python:
In the Python programming language, to work with date and time we need a module known as the Datetime module in python.
This module is built-in in python we did not have to install this module.DateTime module is used to supply the classes in the program. These classes help us to use a large number of functions related to date, time, etc in our program.
To use datetime module in python in our program and print the present date and time, simply use the below lines of code in our program:
present = datetime.datetime.now()
Output of this code is shown below:
It prints the current date in the yy/mm/day format and the current time of your time zone. This serves as simple datetime module in python example.
📙Options available with the datetime module:
Datetime module has several options to take the information from the date object. some of these methods are shown below:
🧐strftime() method in python:
This method helps us to convert the datetime object into several string methods for processing.
To use strftime method in python method we have to import the datetime class from the datetime module.
strftime example python 3: To get the year data from the datetime printed output use the below lines of code in your program.
from datetime import datetime
present = datetime.now() # present date and time
print(present) # full output of datetime class
year = now.strftime("%Y") # to separate year data from the full output of datetime class
Output of these lines of code is shown below:
To print the weekday using datetime module use the following lines of code given below:
Thats all about module Datetime.In the next article we will discuss more modules we are going to use in our virtual assistant.
So stay tuned for next article. Hope you are liking this series of articles. Meet you in next article.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
I am a data science enthusiast. I love to learn new technology 🛠🛠.you can reach me at this url www.linkedin.com/in/ayushbajpai47
Page Views :
Published Date :