from datetime import date import calendar current_date = date.today() print(calendar.day_name[current_date.weekday()]Output:Monday Explanation:In the above code, we first start by importing the datetime module which is a module used in Python to work with dates and time. Then we import ...
datetime.strptime(date, '%d %m %Y').weekday() #this statement returns an integer corresponding to the day of the week return (calendar.day_name[born]) #this statement returns the corresponding day name to the integer generated in the previous statement #To get the input from the user #...
get datetime string date format="YYYYMMDDHHMMSS" ''' return year+mon+day+hour+min+sec def get_day_of_day(n=0): ''' if n>=0,date is larger than today if n<0,date is less than today date format = "YYYY-MM-DD" ''' if n<0: n = abs(n) ''' datetime.timedelta(days=n)返...
"day": day, "current_date": f"{year}-{month}-{day}" } return params def get_current_week(): ''' 当周 :return: ''' start_time, end_time = datetime.date.today(), datetime.date.today() one_day = datetime.timedelta(days=1) while start_time.weekday() != 0: start_time -= ...
from time import * #a function to find your age def age(): print "Enter Your Date of Birth" d=input("Day:") m=input("Month:") y=input("Year:") #get the current time in tuple format a=gmtime() #difference in day dd=a[2]-d ...
'date','day','dst','fold','fromordinal','fromtimestamp','hour','isocalendar','isoformat','isoweekday','max','microsecond','min','minute','month','now','replace','resolution','second','strftime','strptime','time','timestamp','timetuple','timetz','today','toordinal','tzinfo',...
def get_day(date, step=0): l = date.split("-") y = int(l[0]) m = int(l[1]) d = int(l[2]) old_date = datetime.datetime(y, m, d) new_date = (old_date + datetime.timedelta(days=step)).strftime('%Y-%m-%d')
from time import * #a function to find your age def age(): print "Enter Your Date of Birth" d=input("Day:") m=input("Month:") y=input("Year:") #get the current time in tuple format a=gmtime() #difference in day dd=a[2]-d ...
from ztime import dateutil date_string = '2022-01-01 11:12:13' date = dateutil.parser.parse(date_string) print('Parsed Date:', date) # 替换年份为2023 # 其他参数:year,month,day,hour,minute,second,microsecond,tzinfo new_date = date.replace(year=2023) ...
Current date and time: Tue Aug 6 11:14:11 2019 ———- Local time : time.struct_time(tm_year=2019, tm_mon=8, tm_mday=6, tm_hour=11, tm_min=14, tm_sec=11, tm_wday=1, tm_yday=218, tm_isdst=0) ———- Local time in UTC format : ...