简体   繁体   English

如何将此日期格式化为日 - 月 - 年

[英]How can I format this date into Day - Month - Year

def UpdateDate(WorstDate):
    Day = WorstDate[5:]
    Month = WorstDate[2:6]
    Year = WorstDate[:2]
    return Day + "-" + Month + "-" + Year
print(UpdateDate("202011Jan"))

I keep getting (1Jan-2011-20) I'm no pro so any advice would be appreciated.我不断收到 (1J-2011-20) 我不是专业人士,所以任何建议将不胜感激。

This might be useful:这可能有用:

import time

timestr = time.strftime("%d-%m-%Y")

print(timestr)

Below is the updated solution:以下是更新后的解决方案:


    def UpdateDate(WorstDate):
        Day = WorstDate[4:6]
        Month = WorstDate[6:]
        Year = WorstDate[:4]
        return Day + "-" + Month + "-" + Year

    print(UpdateDate("202011Jan"))


Output:输出:

11-Jan-2020

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将日,月,年转换为日期格式? - How to convert day,month,year into date format? 如何将日期从日-月-年重新格式化为年-月-日? - How can I reformat date from day-month-year to year-month-day? 如何将星期几、月份、日期转换为年 - 月 - 日期 - How can I convert day of week, Month, Date to Year - Month - Date 从年月日更改日期格式 - Changing date format from year month day 将日期格式转换为“月-日-年” - Convert date format to 'Month-Day-Year' 给定日期列表,我如何将它们组合/格式化为字符串,例如“Day1-Day3,Day5 Month Year” - Given a list of dates, how can I combine/format them as a string like "Day1-Day3, Day5 Month Year" 如何将日期格式(星期几,月,日,年)更改为熊猫可读格式? - How to change date format (Day of week, Month, Day, Year) to a pandas readable format? 如何将字符串转换为日期对象并分别获取年、月和日? - How can I convert a string into a date object and get year, month and day separately? 如何从数据格式创建日期年月日1日2日3日4.........day31 - how to create date from data format year month day1 day2 day3 day4 .........day31 如何在熊猫数据框中将日期类型从“year_week”更改为“day_month_year”格式? - How to change date type from 'year_week' to 'day_month_year' format in pandas dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM