迄今为止的秒数转换 [英] Number of seconds to date conversion

查看:75
本文介绍了迄今为止的秒数转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,其中一列是销售日期。不知道为什么,但是R会将其转换为数字,为什么执行任何操作。我想将其转换回R中的 POSIXct 日期格式。为此,我使用下面的代码,但得到了意外的结果

I have a data set where one of the columns is sales date. Don't know why, but R converts it to numeric why performing any operation. I would like to convert it back to POSIXct date format in R. To do the same, I am using below code, but getting an unexpected result

 x= as.Date(1448208000, origin = "1970-01-01")
[1] "3967028-10-31"
 x= as.POSIXct(x,"%Y-%m-%d")

我对R中的日期格式不太满意,在这方面会提供任何帮助。

I am not good with dates format in R and would appreciate any kind of help in this regard.

推荐答案

1448208000 是自unix时代以来的秒数,并且是POSIX对象的数字表示形式。要将其转换回 POSIXct

1448208000 is the number of seconds since the unix epoch, and is the numeric representation of a POSIX object. To convert it back to POSIXct you want

as.POSIXct(1448208000, origin = "1970-01-01")






您可能还想确保时区正确;看到这两个命令之间的区别


You'll also probably want to ensure the timezone is correct too; see the difference between these two commands

as.POSIXct(1448208000, origin = "1970-01-01", tz = "UTC")
# [1] "2015-11-22 16:00:00 UTC"

as.POSIXct(1448208000, origin = "1970-01-01", tz = "Australia/Melbourne")
# [1] "2015-11-23 03:00:00 AEDT"

这篇关于迄今为止的秒数转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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