R : POSIXctãas.Date() ããæã«tzãæå®ããªãå ´åãPOSIXctã®ã¿ã¤ã ã¾ã¼ã³ã«ä½ãè¨å®ããã¦ãã¦ãUTCã¨ã¿ãªãã¦å¦çããã¦ããã®ã§ã¯?
POSIXct
ã¯ã¿ã¤ã ã¾ã¼ã³ãä¼´ã£ãæ¥æåã§ããããããas.Date()
ã¨ããçµã¿è¾¼ã¿é¢æ°ã«æ¸¡ãã¨ãDate
ã¨ããæ¥æåã«å¤æã§ããã
ãã®é¢æ°ã®æåã«ã©ãã«ãéåæãããã
ã©ãããã®é¢æ°ãPOSIXctãas.Date() ããæã«tzãæå®ããªãå ´åãPOSIXctã®ã¿ã¤ã ã¾ã¼ã³ã«ä½ãè¨å®ããã¦ãã¦ãUTCã¨ã¿ãªãã¦å¦çããã¦ãã
ãããªã®ã ã
ä¾
> as.POSIXct('2015-01-01 00:00:00') [1] "2015-01-01 JST" > as.Date(as.POSIXct('2015-01-01 00:00:00')) [1] "2014-12-31" > as.Date(as.POSIXct('2015-01-01 00:00:00', tz="UTC")) [1] "2015-01-01"
å®è£ ãèªãã§ã¿ã
as.Date
ã¯Rã«ããã¦ãç·ç§°é¢æ°
ã¨å¼ã°ããã¿ã¤ãã®é¢æ°ã§ããã
ããã¯ãä¸ããããå¼æ°ã®åãå¤å®ãã¦ãåã«å¿ãã¦ç°ãªãå¦çãè¡ãä»çµã¿ã§ããã
ãã®ç·ç§°é¢æ°ã®å®è£
ãèªãã«ã¯ä»¥ä¸ã®ããã«ããã
> methods(as.Date) [1] as.Date.IDate* as.Date.POSIXct as.Date.POSIXlt as.Date.character as.Date.date as.Date.dates as.Date.default [8] as.Date.factor as.Date.numeric see '?methods' for accessing help and source code > as.Date.POSIXct function (x, tz = "UTC", ...) { if (tz == "UTC") { z <- floor(unclass(x)/86400) attr(z, "tzone") <- NULL structure(z, class = "Date") } else as.Date(as.POSIXlt(x, tz = tz)) } <bytecode: 0x5d0f708> <environment: namespace:base>
as.Date.POSIXct
ã®tz
ã«ããã©ã«ãå¼æ°ã¨ãã¦"UTC"
ãæå®ããã¦ããã
function (x, tz = "UTC", ...)
ããã§ã¯ãå¼æ°ã®POSIXct
ã®tz
ããªãã§ããã(as.Date()
ã®tz
ãæ示çã«æå®ãããªãéã)"UTC"
ã¨ãã¦å¦çããã¦ãã¾ãã
(â¦ã¨ãèªã¿åã£ããã§ããåã£ã¦ã¾ããã? ä½ãè¦è½ã¨ãããã£ããæãã¦ä¸ããã)
ç¾ç¶ã®as.Date
ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãã¶ã¤ã³ã®èª²é¡
ãã®ãããªAPIã®ãã¶ã¤ã³ã¯ãã¼ã«ãã«ã¼ãã®ååã«ã®ã£ã¨ã£ã¦ããªãã¨æããã
ãã®é¢æ°ã¯ããas.Date()
ã使ãæã¯tz
ãæ示çã«æå®ããå¿
è¦ããããã¨ããèªèãæ¬ ãã人ã«å¯¾ãã¦æçãææãä¸ãããã¨ã«ãªãã
ããèªåãå®è£ è ã ã£ãã?
tz
ãæ示çã«æå®ããªãå ´åã«ä¾å¤ãåºãããå¼æ°ã¨ãªã£ãPOSIXct
ã®tz
ã使ç¨ããããã«ããã- ä»ããå¤ãããå¾æ¹äºææ§ãåãäºã«ãªãã®ã§ç¡çã ãããã©â¦
èªåããããããã¶ã¤ã³ãããªãããã«æ°ãã¤ãã¾ãâ¦