utils.py 568 Bytes
Newer Older
Wei Shoulin's avatar
utils  
Wei Shoulin committed
1
2
from datetime import datetime
    
3
def is_valid_datetime_format(date_str: str) -> bool:
Wei Shoulin's avatar
utils  
Wei Shoulin committed
4
    try:
5
6
        # 尝试不带时区的基础格式
        datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
Wei Shoulin's avatar
utils  
Wei Shoulin committed
7
8
        return True
    except ValueError:
9
10
11
12
13
14
        try:
            # 尝试ISO格式(带或不带时区)
            datetime.fromisoformat(date_str.replace(' ', 'T'))
            return True
        except ValueError:
            raise ValueError("Incorrect data format")
Wei Shoulin's avatar
Wei Shoulin committed
15
16
17
    
def get_current_time() -> str:
    return datetime.now().strftime('%Y-%m-%d %H:%M:%S')