R/EpochMilli2Date.R

Defines functions EpochMilli2Date

Documented in EpochMilli2Date

#' Convert an epoch in milliseconds into a date
#'
#' @param x A [character] or a [numeric] representing an epoch in milliseconds
#' @param timezone A [character] with the time zone used for the conversion
#'
#' @return A [POSIXct], the date corresponding to the epoch
#' @export
#'
#' @examples
#' epoch <- Date2EpochMilli(as.numeric(Sys.time()))
#' EpochMilli2Date(epoch)
#'
EpochMilli2Date <- function(x, timezone = "GMT") {
  return(
    as.POSIXct(as.numeric(x)/1000, tz = timezone, origin = "1970-01-01")
  )
}

Try the Rthingsboard package in your browser

Any scripts or data that you put into this service are public.

Rthingsboard documentation built on Jan. 19, 2022, 5:08 p.m.