How to Get Current Date and Time in Python?
This simple article demonstrates of how to get current date and time in python. you'll learn python get current date and time. step by step explain python get today's date and time. Here you will learn python get current date and time without time.
In this post, i will give you three examples to getting current date and time in python. we will use datetime module to get current date and time. so let's see following examples with output:
Example 1: Python Get Today's Date
from datetime import date # Get Today's Date today = date.today() print("Today's date is :", today)
Today's date is : 2022-05-28
Example 2: Python Get the Current Date and Time
from datetime import datetime # Current date and time object now = datetime.now() print("now() time =", now) # dd/mm/YY H:M:S currentDateTime = now.strftime("%d/%m/%Y %H:%M:%S") print("Current Date and Time =", currentDateTime)
now() time = 2022-05-28 09:29:52.455034 Current Date and Time = 28/05/2022 09:29:52
Example 3: Python Current Date with Different Formats
from datetime import date today = date.today() # dd/mm/YY date1 = today.strftime("%d/%m/%Y") print("date1 =", date1) # Textual month, day and year date2 = today.strftime("%B %d, %Y") print("date2 =", date2) # mm/dd/y date3 = today.strftime("%m/%d/%y") print("date3 =", date3) # Month abbreviation, day and year date4 = today.strftime("%b-%d-%Y") print("date4 =", date4)
date1 = 28/05/2022 date2 = May 28, 2022 date3 = 05/28/22 date4 = May-28-2022
I hope it can help you...
We are Recommending you
- PHP Google Recaptcha V2 Example Tutorial
- Laravel Pagination Pretty URL Example
- How to use HttpHeaders in Angular 13?
- Angular 13 Stripe Payment Integration Example
- Laravel 9 REST API with Passport Authentication Tutorial
- Laravel 9 Scout Full Text Search Tutorial
- How to Get Last Executed Query in Laravel 9?
- Laravel 9 Autocomplete Search using Typeahead JS Example
- Angular 13 Google Maps Integration Example
- Angular 13 File Upload with Progress Bar Tutorial
- Angular 13 Reactive Forms Validation Tutorial Example