简体   繁体   中英

convert Julian day number to date time format yyyy-mm-dd hh:mm:ss in R

How to convert Julian day number to date and time if the origin is ("2000-01-01") and I have two Julian day numbers JDN (4822.178270,4822.17840) what is the equivalent date time? the code is

JDN <- c(4822.178270,4822.17840)
temp<- as.Date(JDN +0.5, origin=as.Date("2000-01-01 00:00:00")) # that gave only date as "2013-03-15" "2013-03-15" without time.

# my result should be:

"2013-03-15 16:16:42" "2013-03-15 16:16:53"
as.POSIXct('2000-01-01')+((JDN+0.5)*24*60*60)

This should do it:

JDN <- c(4822.178270,4822.17840)


origin <- lubridate::ymd_hms('2000-01-01 00:00:00')

origin + JDN * 3600*24
#> [1] "2013-03-15 04:16:42 UTC" "2013-03-15 04:16:53 UTC"

Created on 2020-01-22 by the reprex package (v0.3.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM