如何将十进制日期格式(例如2011.580)转换为普通日期格式? [英] How to convert decimal date format (e.g. 2011.580) to normal date format?

查看:543
本文介绍了如何将十进制日期格式(例如2011.580)转换为普通日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将十进制日期格式(从changepoint包中返回cpts.ts()的类型)更改为正常日期格式%Y-%m-%d。示例:

I'm trying to change from the decimal date format (return type of cpts.ts() from the changepoint package) to the normal date format %Y-%m-%d. Example:

cpts.ts(myTimeSeries.BinSeg)
[1] 2001.667 2004.083 2008.750 2011.583 2011.917

实际日期大约是2001年8月,2004年1月,2008年9月,2011年6月/ 7月和2011年12月(我不知道它们是什么,我正在从图表中读取它们。)

The actual dates are sometime around August 2001, January 2004, September 2008, June/July 2011 and December 2011 (I don't know them exactly, I'm reading them off a graph).

我似乎找不到找到将这种格式转换回通常日期的标准方法格式。

I can't seem to find a standard method of converting this format back to the usual date format.

有人可以帮助我吗?

谢谢

推荐答案

使用 lubridate 的结果略有不同:

library(lubridate)
decimals <- c(2001.667, 2004.083, 2008.750, 2011.583, 2011.917)

format(date_decimal(decimals), "%Y-%m-%d")
# [1] "2001-09-01" "2004-01-31" "2008-10-01" "2011-08-01" "2011-12-01"

这篇关于如何将十进制日期格式(例如2011.580)转换为普通日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆