[Python] How to print a date in a regular format?

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    This is my code:

    import datetime
    today = datetime.date.today()
    print(today)


    This prints: 2008-11-22 which is exactly what I want.

    But, I have a list I'm appending this to and then suddenly everything goes "wonky". Here is the code:

    import datetime
    mylist = [datetime.date.today()]
    print(mylist)


    This prints [datetime.date(2008, 11, 22)]. How can I get just a simple date like 2008-11-22?

    Continue reading...

Compartilhe esta Página