创建具有特殊格式的日期序列 [英] Creating a sequence of dates with a special format
本文介绍了创建具有特殊格式的日期序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何创建以下格式的日期序列:从"7月23日10:20"
到"7月30日10:25"
是在"1"
天之前?
I was wondering how I could create a sequence of dates in the following format: from "Jul 23 10:20"
to "Jul 30 10:25"
by "1"
day?
我没有成功尝试了以下内容:
I tried the following without sucess:
seq.Date(as.Date("Jul 23 10:20"), as.Date("Jul 30 10:25"), length.out = 7)
推荐答案
要保留时间,您应该将其转换为实际的日期时间,从中可以轻松构建一次增加1天的序列.您可以使用 strftime
随意设置其格式.
To preserve times you should convert to actual date-times, from which it is easy to build a sequence increasing by 1 day at a time. You can use strftime
to format this as you please.
strftime(seq(as.POSIXct("2020-07-23 10:20"), by = "1 day", length.out = 7), "%b %e %H:%M")
#> [1] "Jul 23 10:20" "Jul 24 10:20" "Jul 25 10:20" "Jul 26 10:20" "Jul 27 10:20"
#> [6] "Jul 28 10:20" "Jul 29 10:20"
这篇关于创建具有特殊格式的日期序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文