Date Formatting with Pendulum

  • Share this:

Code introduction


This function takes a date string and a new date format as input, parses the date string into a pendulum datetime object, and then formats the datetime object into the new format and returns it.


Technology Stack : Pendulum

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_date_format(date, new_format):
    from pendulum import parse
    from pendulum import datetime
    
    # Parse the date string into a pendulum datetime object
    dt = parse(date)
    
    # Format the datetime object into a new format
    new_date_format = dt.format(new_format)
    
    return new_date_format

# JSON explanation                
              
Tags: