1#!/usr/bin/env python3 2 3r""" 4This module contains functions having to do with date time filter. 5""" 6 7from datetime import datetime 8 9 10def convert_string_dateime(date_str, date_format, desired_format): 11 r""" 12 Return a date time formatted from a string datetime. 13 14 Description of arguments(s): 15 date_str Date time string e.g 2021072418161 16 or list ["2021072418161", "20210723163401"] 17 date_format Date time pattern of the string date time 18 e.g '%Y%m%d%H%M%S' 19 desired_format User define format e.g '%m/%d/%Y - %H:%M:%S' 20 """ 21 22 if isinstance(date_str, list): 23 tmp_date = [] 24 for date in date_str: 25 tmp_date.append(datetime.strptime(date, date_format).strftime(desired_format)) 26 return tmp_date 27 else: 28 return datetime.strptime(date_str, date_format).strftime(desired_format) 29