import datetime, calendar, time
date_str =
'2020-05-11'
time_tuple = time.strptime(date_str,
'%y-%m-%d'
)print
(time_tuple)
year, month, day = time_tuple[:3
]print
(year, month, day)
current_date = datetime.date(year, month, day)
print
(current_date)
import datetime, calendar, time
date_str =
'2020-05-11'
time_tuple = time.strptime(date_str,
'%y-%m-%d'
)print
(time_tuple)
year, month, day = time_tuple[:3
]print
(year, month, day)
current_date = datetime.date(year, month, day)
print
(current_date)
# 獲取當前日期
# today1 = datetime.date.today()
# today2 = datetime.date.today()
current_date1 = current_date
current_date2 = current_date
# 指定時間週期
interval_one_day = datetime.timedelta(days=1)
interval_seven_day = datetime.timedelta(days=7)
# 獲取周一和週日的判斷條件(周一為0,週日為6)
m1 = calendar.monday
m2 = calendar.sunday
# 獲取上週周一的時間
if current_date1.weekday(
)!= m1:
while current_date1.weekday(
)!= m1:
current_date1 -= interval_one_day
current_date1 -= interval_seven_day
else
: current_date1 -= interval_seven_day
print
(current_date1)
# 獲取上週週日的時間
if current_date2.weekday(
)!= m2:
while current_date2.weekday(
)!= m2:
current_date2 -= interval_one_day
else
: current_date2 -= interval_seven_day
print
(current_date2)
import datetime, calendar, time
defget_n_day()
: date_str =
'2020-05-17'
time_tuple = time.strptime(date_str,
'%y-%m-%d'
)print
(time_tuple)
year, month, day = time_tuple[:3
]print
(year, month, day)
current_date = datetime.date(year, month, day)
print
(current_date)
# 獲取當前日期
# today1 = datetime.date.today()
# today2 = datetime.date.today()
current_date1 = current_date
current_date2 = current_date
# 指定時間週期
interval_one_day = datetime.timedelta(days=1)
interval_seven_day = datetime.timedelta(days=7)
# 獲取周一和週日的判斷條件(周一為0,週日為6)
m1 = calendar.monday
m2 = calendar.sunday
# 獲取下週周一的時間
if current_date1.weekday(
)!= m1:
while current_date1.weekday(
)!= m1:
current_date1 += interval_one_day
else
: current_date1 += interval_seven_day
print
(current_date1)
# 獲取下週週日的時間
if current_date2.weekday(
)!= m2:
while current_date2.weekday(
)!= m2:
current_date2 += interval_one_day
current_date2 += interval_seven_day
print
(current_date2)
get_n_day(
)
根據當前時間獲取本週,下週,上週日期
實現點選按鈕更改周,並獲取本週,上週,下週對應的具體日期 借鑑了一些網上的方法 定義 datetime begindate getweekupofdate datetime.now,dayofweek.monday,0 預設開始時間為本週周一 datetime enddate getweekupof...
獲取傳入時間所在星期的時間範圍
在開發中,會遇到切換時間的需求,普通的加減一天,或者加減乙個月都很通用,今天給大家介紹的是獲取傳入時間所在星期的時間範圍,這樣就可以加減一周了。public class mathweekutils return zhou time1 獲取當前星期的周一,週日 param date param dat...
當前時間,本週,本月,本年的時間範圍獲取
js中獲得當前時間是年份和月份,形如 201208 獲取完整的日期 var date new date var year date.getfullyear var month date.getmonth 1 month month 10 0 month month var mydate year.t...