基于隐蔽时间的字符串到数字

问题描述

我在SQL表中有2个字段: 1:今天的日期 2:时间估计

时间估计是自然语言,因此可以是任何字符串变体:明天,日期,几天,日期范围等。我需要将时间估计字符串转换为日期/时间数值。例如,几天后是3。

解决方法

您可以在linux上使用date命令,尽管您需要进行一些小的调整。

例如明天(不区分大小写):

date -d tommorrow

和python中的

estimate = "tommorrow"
date = os.popen(f'date -d {estimate}').read()

“几天内”选项太含糊,无法立即转换为日期,因此您可以在几天内将date命令设为“ + 3days”参数。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...