utils.py 375 Bytes
Newer Older
Wei Shoulin's avatar
utils  
Wei Shoulin committed
1
2
3
4
5
6
7
from datetime import datetime
    
def is_valid_datetime_format(date_str: str, format='%Y-%m-%d %H:%M:%S') -> bool:
    try:
        datetime.strptime(date_str, format)
        return True
    except ValueError:
Wei Shoulin's avatar
Wei Shoulin committed
8
9
10
11
        raise ValueError(f"Incorrect data format, should be {format}")
    
def get_current_time() -> str:
    return datetime.now().strftime('%Y-%m-%d %H:%M:%S')