将时间和日期字符串从CSV导入AppEngin中的DateProperty/TimeProperty

2024-04-20 14:40:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从csv文件中读取一个包含日期格式为“XX/XX/XXXX”的单元格的文件,以及分别使用App Engine(python)中的DateProperty和TimeProperty包含时间格式“XX:XX:XX”的单元格的文件。我最初使用DateTimeProperty执行了类似的操作:

x = ndb.DateTimeProperty()
row[1] = datetime.datetime.strptime(row[1], "%m/%d/%Y")
x = row[1]

但这也返回了一个空时间00:00:00,我不想要。在

我将.date()添加到 日期时间.日期时间.strptime(第[1]行,“%m/%d/%Y”) 但有一个错误: “BadValueError:应为datetime,已获取日期时间.time(23,59)” 其中23,59来自一个时间单元“23:59:00”。在

编辑:我可以通过更改x=ndb.DateTimeProperty只对x=ndb.DateProperty属性(),但是,当在app engine上的Datastore Viewer中查看时,除了日期之外,它还显示00:00:00;我只是在查找日期。在


Tags: 文件csvappdatetime格式时间enginerow