0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

lambda

Posted at
from datetime import datetime, timezone, timedelta  # 确保导入了 timedelta

# ... 其余代码 ...

def format_timestamp(timestamp_str):
    """
    将时间戳字符串转换为日本标准时间(JST)格式
    """
    if timestamp_str:
        try:
            # 解析时间戳,包含时区信息
            timestamp = datetime.strptime(timestamp_str, '%Y-%m-%dT%H:%M:%S.%f%z')
            # 创建日本时区(UTC+9)
            jst_timezone = timezone(timedelta(hours=9))
            # 转换为日本时区
            jst_time = timestamp.astimezone(jst_timezone)
            return jst_time.strftime('%Y-%m-%d %H:%M:%S %Z')
        except ValueError as e:
            print(f"时间戳解析错误: {e}")
            return 'N/A'
    else:
        return 'N/A'

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?