[英]Convert 24 hours date format to 12 hour format in R
I have a 24 hours time format vector. 我有24小时时间格式向量。
time24 <- c("10:43:12", "10:54:25", "11:54:21", "23:07:20")
I need to convert it to 12 hour format. 我需要将其转换为12小时格式。
"10:43 AM", "10:54 AM", "11:54 AM", "11:07 PM"
I tried using strptime but no luck. 我尝试使用strptime但没有运气。 Any help will be appreciated.
任何帮助将不胜感激。
You can use format
around the strptime
output to get the expected output. 您可以使用
strptime
输出周围的format
来获得预期的输出。
format(strptime(time24, '%H:%M:%S'), '%I:%M %p')
#[1] "10:43 AM" "10:54 AM" "11:54 AM" "11:07 PM"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.