是否可以将日期时间保存到 DynamoDB? [英] Is it possible to save datetime to DynamoDB?

查看:14
本文介绍了是否可以将日期时间保存到 DynamoDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个代码:

users_table = Table(users_table_name, connection=Core.aws_dynamodb_connection)
users_table.put_item(data={
  "login": login,
  "password": hashlib.sha256(password.encode("utf-8")).hexdigest(),
  "profile": profile,
  "registration_date": datetime.now() # PROBLEM IS HERE
})

但是当我运行它时,它失败并出现错误:

But when I run it, it fails with error:

TypeError:值2015-01-12 05:02:57.053131"的不支持类型< type 'datetime.datetime'>"

TypeError: Unsupported type "< type 'datetime.datetime' >" for value "2015-01-12 05:02:57.053131"

我尝试了很多方法,但似乎无法将 datetime 保存到 DynamoDB.顺便说一句,它在 MongoDB 中运行良好.

I've tried a lot of ways, but it seems that it isn't possible to save datetime to DynamoDB. Btw it works fine in MongoDB.

有什么解决办法吗?

推荐答案

好的,我看到 DynamoDB 不支持任何日期类型.所以唯一的解决方案是使用类unix的时间作为整数,或者将日期保存为字符串.

Okay, I see that DynamoDB does not support any date types. So the only solution is to use unix-like time as integer, or save date as string.

这篇关于是否可以将日期时间保存到 DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆