如何提取这种时间戳的小时?

How to extract the hour of this kind of timestamp?

这是我的时间戳的样子

date1 = timestamp[1]

date1
[1] 07.01.2016 11:52:35
3455 Levels: 01.02.2016 00:11:52 01.02.2016 00:23:35 01.000:30:21    31.01.2016 23:16:18

当我尝试提取小时时,我得到一个无效的 'trim' 参数。谢谢!

 format(date1, "%I")

 Error in format.default(structure(as.character(x), names = names(x), dim = dim(x),  : 

无效的'trim'参数

如何从此时间戳中提取单个组件,例如小时。

首先需要解析时间

d = strptime(date1,format = '%d.%m.%Y %H:%M:%S')

然后使用 lubridate 提取小时等部分

library(lubridate)
hour(d)
minute(d)

基数 R:

format(strptime(x,format = '%d.%m.%Y %H:%M:%S'), "%H")
[1] "11"

数据

x <- as.factor("07.01.2016 11:52:35")