您的位置:首页 > 游戏 > 游戏 > 公众号平台登陆入口_网站娱乐一条龙搭建_网络运营_太原百度seo排名

公众号平台登陆入口_网站娱乐一条龙搭建_网络运营_太原百度seo排名

2025/4/12 4:57:07 来源:https://blog.csdn.net/weixin_40428902/article/details/146442472  浏览:    关键词:公众号平台登陆入口_网站娱乐一条龙搭建_网络运营_太原百度seo排名
公众号平台登陆入口_网站娱乐一条龙搭建_网络运营_太原百度seo排名

错误:TypeError: Object of type JsonResponse is not JSON serializable

一个参数引发的问题,

我想把 2025-03-22T07:07:42.443Z" 转成没有T的那种,

就写了一个函数 原来的函数:

def get_create_time(str): target_tz = pytz.timezone('Asia/Shanghai') local_time = create_time.astimezone(target_tz) return local_time.strftime("%Y-%m-%d %H:%M:%S") 

引发的问题是:TypeError: Object of type JsonResponse is not JSON serializable

意思是在它说当前代码里, get_create_time 函数期望传入的 create_time 是 datetime 对象。

当我把 create_time 作为字符串传入时,

代码执行到 local_time = create_time.astimezone(target_tz) 就会报错,

原因在于字符串类型没有 astimezone 方法。

所以要改成

def get_create_time(create_time):target_tz = pytz.timezone('Asia/Shanghai')local_time = create_time.astimezone(target_tz)return local_time.strftime("%Y-%m-%d %H:%M:%S") # return formatted_time

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com