카타 7급 Converting 12-hour time to 24-hour time

R[ | ]

to24hourtime <- function(hour, minute, period){
  if( hour == 12 ) hour = 0
  if( period == 'pm' ) hour = hour + 12
  if( hour<10 ) hour = paste("0",hour,sep="")
  if( minute<10 ) minute = paste("0",minute,sep="")
  paste(hour,minute,sep="")
}
to24hourtime <- function(hour, minute, period) {
  if (hour == 12) { hour = 0 }
  if (period == 'pm') { hour = hour + 12 }
  sprintf("%02d%02d", hour, minute)
}
to24hourtime <- function(hour, minute, period){
  hour <- ifelse(period == 'pm', (hour %% 12 + 12), hour %% 12)
  return(sprintf("%.2d%.2d", hour, minute))
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}