Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

The below is the character vector:

times <- c("2020-04-15T03:30:05.197Z", "2020-04-15T03:30:05.366Z", "2020-04-15T03:30:05.530Z")

I know that I need to convert it to a lubridate datetime object or a POSIXct object. The following does not work:

as_datetime(link_log$createdAt,

            format = "%Y-%m-%d%T%H:%M:%S")

1 Answer

0 votes
by (107k points)

I think that the lubridate's ymd_hms should work in your case. Kindly refer to the following code:

options(digits.secs=6)

lubridate::ymd_hms(times)

#[1] "2020-04-15 03:30:05.197 UTC" "2020-04-15 03:30:05.366 UTC" 

#    "2020-04-15 03:30:05.529 UTC"

If you are a beginner and wants to know more about R then do check out the following R programming tutorial that will help you in learning R from scratch. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...