我找不到此日期时间的正确格式。我尝试了几种格式,dd($image)
是我在下面的示例中可以找到的最接近的格式。
Illuminate\Http\UploadedFile {#270 ▼
-test: false
-originalName: "korabl_more_zakat_luna_63381_1920x1080.jpg"
-mimeType: "image/jpeg"
-error: 0
#hashName: null
path: "/tmp"
filename: "phpfJOzTp"
basename: "phpfJOzTp"
pathname: "/tmp/phpfJOzTp"
extension: ""
realPath: "/tmp/phpfJOzTp"
aTime: 2020-02-07 18:51:11
mTime: 2020-02-07 18:51:11
cTime: 2020-02-07 18:51:11
inode: 34603072
size: 425567
perms: 0100600
owner: 1000
group: 1000
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
结果:
%Y/%m/%d%I:%M:%S%p
答案 0 :(得分:4)
您可以使用参数infer_datetime_format=True
解决此问题。这是一个示例:
df = {}
df['datetime'] = '2019-11-13 16:28:05.779'
df['datetime'] = pd.to_datetime(df['datetime'], infer_datetime_format=True)
print(df['datetime'])
print(type(df['datetime'])
输出:
2019-11-13 16:28:05.779000
<class 'pandas._libs.tslibs.timestamps.Timestamp'>
答案 1 :(得分:4)
在猜测自己有大熊猫之前,请先进行猜测
df['datetime'] = pd.to_datetime(df['datetime'], infer_datetime_format=True)
0 2019-11-13 16:28:05.779
Name: datetime, dtype: datetime64[ns]
答案 2 :(得分:-1)
以下是带有正确格式字符串的pandas.to_datetime()
调用:pd.to_datetime(df['datetime'], format="%Y/%m/%d %H:%M:%S")
您错过了一个空格,%I
停留了12个小时(示例时间为16:28
,而%p
引用了等效于AM或PM的语言环境。