Answers for "how to get current date time in python"

32

python current date

from datetime import date

today = date.today()
print("Today's date:", today)
Posted by: Guest on April-15-2020
8

python get the current date

# Example usage:
import datetime
date_time = datetime.datetime.now()
print(date_time)
--> 2020-10-03 15:29:54.822751

# From the date_time variable, you can extract the date in various
# custom formats with .strftime(), for example:
date_time.strftime("%d/%m/%Y")
--> '03/10/2020' # dd/mm/yyyy

date_time.strftime("%m/%d/%y")
--> '10/03/20' # mm/dd/yy

date_time.strftime("%Y/%m/%d")
--> '2020/10/03'

date_time.strftime("%Y-%m-%d")
--> '2020-10-03'

date_time.strftime("%B %d, %Y")
--> 'October 03, 2020'

# Key for other custom date/time formats:
Directive	Description								Example
%a			Weekday, short version					Wed	
%A			Weekday, full version					Wednesday	
%w			Weekday as a number 0-6, 0 is Sunday	3	
%d			Day of month 01-31						31	
%b			Month name, short version				Dec	
%B			Month name, full version				December	
%m			Month as a number 01-12					12	
%y			Year, short version, without century	18	
%Y			Year, full version						2018	
%H			Hour 00-23								17	
%I			Hour 00-12								05	
%p			AM/PM									PM	
%M			Minute 00-59							41	
%S			Second 00-59							08	
%f			Microsecond 000000-999999				548513	
%z			UTC offset								+0100	
%Z			Timezone								CST	
%j			Day number of year 001-366				365	
%U			Week number of year 00-53				52	
%c			Local version of date and time			Mon Dec 31 17:41:00 2018	
%x			Local version of date					12/31/18	
%X			Local version of time					17:41:00	
%%			A % character							%
Posted by: Guest on October-03-2020
6

get time pithon

"""Imports the datetime package from the Python library"""
from datetime import datetime

"""Sets the variable now to the current date and time"""
now = datetime.now()

"""The variable current_time contains the string values of the current time"""
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
Posted by: Guest on May-29-2020
1

print time in python

import time

t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print(current_time)
Posted by: Guest on June-23-2020
3

how to print time python

import datetime
datetime.datetime.now()
datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)

print(datetime.datetime.now())
#2009-01-06 15:08:24.789150
Posted by: Guest on June-02-2020

Code answers related to "how to get current date time in python"

Python Answers by Framework

Browse Popular Code Answers by Language