R/Date2EpochMilli.R

Defines functions Date2EpochMilli.numeric Date2EpochMilli.POSIXt Date2EpochMilli

Documented in Date2EpochMilli Date2EpochMilli.numeric Date2EpochMilli.POSIXt

#' Convert a date into an epoch in milliseconds
#'
#' This function allows to convert epoch timestamp in seconds to an epoch in milliseconds
#'
#' @param ts a [numeric] representing an epoch in seconds or a [POSIXt] date
#'
#' @return a [character] of the epoch in milliseconds
#' @export
#'
#' @rdname Date2EpochMilli
#' @examples
#' Date2EpochMilli(as.numeric(Sys.time()))
#'
Date2EpochMilli <- function(ts) {
  UseMethod("Date2EpochMilli")
}

#' @rdname Date2EpochMilli
#' @export
Date2EpochMilli.POSIXt <- function(ts) {
  Date2EpochMilli(as.numeric(ts))
}

#' @rdname Date2EpochMilli
#' @export
Date2EpochMilli.numeric <- function(ts) {
  paste0(as.character(floor(ts)), "000")
}

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.