r - Disappearing seconds when time becomes midnight -


i had code takes in time , takes way set number of seconds. works fine apart edge case when take away number of seconds end @ midnight. in code using when situation occurs, seconds part of time disappears. subsequent code fails because expecting time in specific format.

any ideas how deal situation subsequent code doesn't give unexpected results.

ignore time zones in following - i'm interested in disappearing seconds.

basetime <- "2015-03-25 00:01:00" adjustment <- 30 gmt1 <- strptime(basetime,"%y-%m-%d %h:%m:%s")  gmtadj <- gmt1 - adjustment gmtadj # [1] "2015-03-25 00:00:30 edt"  gmt <- as.posixct(strptime(as.character(gmtadj),"%y-%m-%d %h:%m:%s"),tz = "gmt") gmt # [1] "2015-03-25 00:00:30 gmt"  adjustment <- 60 gmt1 <- strptime(basetime,"%y-%m-%d %h:%m:%s") gmtadj <- gmt1 - adjustment gmtadj # [1] "2015-03-25 edt"  gmt <- as.posixct(strptime(as.character(gmtadj),"%y-%m-%d %h:%m:%s"),tz = "gmt") gmt # [1] na 

as mrflick said, if don't default format when converting posixct character, need explicitly specify format in as.character call.

r> as.character(gmtadj, "%y-%m-%d %h:%m:%s") [1] "2015-03-25 00:00:00" 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -