Getting String Representation of the given Date and Time Object in R Programming – strftime() Function

strftime() function in R Language is used to convert the given date and time objects to their string representation.

Syntax: strftime(time)

Parameters:
time: specified time object

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strftime function
  
# Specifing a date and time
x <- "2020-06-01 16:15:10 EST"
  
# Calling strftime() function
strftime(x)       

chevron_right


Output:

[1] "2020-06-01 16:15:10"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strftime function
  
# Specifing a date and time using
# as.Date( ) function which converts
# the character data to dates.
x <- as.Date("2020-06-17 12:10:20 EST")
  
# Calling the strftime() function using the % F format
# which is equivalent to % Y-% m-% d (the ISO 8601 date format)
y <- strftime(x, '% F')
  
# Getting string representation of
# the given date and time object
y

chevron_right


Output:

[1] "2020-06-17"
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.