首页 > 解决方案 > 如何将字符串转换为时间

问题描述

我有一列格式为“17:24:00”的字符串。我想转换成时间格式。当我使用 strptime 函数时,它会在时间前面添加日期。我不希望这种情况发生。任何人都知道如何避免添加日期。

chr [1:2075259] "17:24:00" "17:25:00" "17:26:00" "17:27:00" "17:28:00" ...

我试过这个 -

hpc$time<-strptime(hpc$time,format='%H:%M:%S')

它给了我以下结果-

POSIXlt[1:2075259], format: "2020-06-15 17:24:00" "2020-06-15 17:25:00" "2020-06-15 17:26:00" ...

标签: rtime-format

解决方案


推荐阅读