如何将小数转换为POSIX时间 [英] How convert decimal to POSIX time

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

问题描述

我从此处使用函数 来计算日出和日落,它会返回:

 日出日落
6.49055593325792 18.2873900837081

我正在苦苦挣扎(尝试 strftime POSIXct as.Date 函数)将其转换为实时,但到目前为止没有成功。



像往常一样,任何建议都将不胜感激。

解决方案

@Arun的策略有效,但是这样做可能会更容易:

  x<-c(6.49055593325792,18.2873900837081)
今天< -as.POSIXct('2012-01-23 00 :00:00 EST')今天
+(3600 * x)

# 2012-01-23 06:29:26 EST 2012-01-23 18:17: 14 EST

这也会让您秒数。

I use a function from here to calculate the sunrise and sunset and it returns:

         sunrise           sunset
6.49055593325792 18.2873900837081

I am struggling (trying with strftime, POSIXct or as.Date functions) to convert it to real time, but so far without success.

As always, any suggestion is greatly appreciated.

解决方案

@Arun's strategy works, but it might be easier to just do:

x <- c(6.49055593325792, 18.2873900837081)
today<-as.POSIXct('2012-01-23 00:00:00 EST')
today + (3600*x)

# "2012-01-23 06:29:26 EST" "2012-01-23 18:17:14 EST"

That will get you the seconds as well.

这篇关于如何将小数转换为POSIX时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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