如何从此字符串中提取当前月份?

问题描述 投票:0回答:2

在下面的给定代码中,我想获取当前月份(如果今天运行,则为10月),而不是"current_month"中的monthpage

如何完成?

"file/monthly/current_month"
python python-3.x text-search
2个回答
2
投票
def CurrentMonth(self):  
    monthpage = "file/monthly/current_month"
    page = Page
    old_text = page.get(get_redirect=True)

用实际的当前月份名称替换from datetime import datetime now = datetime.now() monthpage.replace('current_month',now.strftime("%B")) 变量中的"current_month"字符串


0
投票

简单。使用日期时间库!

monthpage
© www.soinside.com 2019 - 2024. All rights reserved.