convert datetime from string r

# Step 1: Load the necessary library
library(lubridate)

# Step 2: Create a sample datetime string
datetime_string <- "2023-12-13 14:30:45"

# Step 3: Convert the datetime string to a POSIXct object
datetime_posix <- as.POSIXct(datetime_string, format = "%Y-%m-%d %H:%M:%S")

# Step 4: Print the original datetime string and the converted POSIXct object
cat("Original Datetime String:", datetime_string, "\n")
cat("Converted POSIXct Object:", datetime_posix, "\n")