r - R时间格式转换
问题描述
我几乎完成了我的脚本,但我的日期格式有问题。我安装了使用 as_date 函数的 lubridate 包,但它没有给我我想要的(日期)。“时间”是我的变量,我把它的描述放在下面。
我没有放我的整个脚本,因为我关心的只是这个格式问题(这意味着一个巨大的 netcdf 文件无法下载)
请问你能帮帮我吗 ?
class(time)
[1] "array"
head(time)
[1] 3573763200 3573774000 3573784800 3573795600 3573806400 3573817200
tunits
$long_name
[1] "time in seconds (UT)"
$standard_name
[1] "time"
$units
[1] "seconds since 1900-01-01T00:00:00Z"
$axis
[1] "T"
$time_origin
[1] "01-JAN-1900 00:00:00"
$conventions
[1] "relative number of seconds with no decimal part"
#conversion
date = as_date(time,tz="UTC",origin = "1900-01-01")
head(date)
[1] "-5877641-06-23" "-5877641-06-23" "-5877641-06-23" "-5877641-06-23"
[5] "-5877641-06-23" "-5877641-06-23"
解决方案
自 1900 年 1 月 1 日以来的时间以秒为单位。使用以下方法将值转换为time
实际日期将按以下方式工作:seconds
lubridate
lubridate::ymd("1900-01-01") + lubridate::seconds(3573763200)
您可以对其进行矢量化:
lubridate::ymd("1900-01-01") + lubridate::seconds(time)
推荐阅读
- php - Laravel 中的查询构建器(GROUP BY)
- javascript - 加扰单选按钮数据
- android - 如何在 PreferenceScreen 中创建工具栏?
- css - 减:如何在 nth-child 中引用父级
- swift - 在 Swift 中是否可以要求关联类型符合关联类型的关联协议?
- php - PHP preg_match url中已有特定单词之后的任何文本
- node.js - Discord Bot 在没有权限时发生错误
- sml - 如何在 SML 记录中具有函数返回值
- xaml - 从视图访问对象的属性
- python - 没有 HTTP 身份验证的 Python Twisted 身份验证