Parsing Date and Time in R Programming – strptime() Function

strptime() function in R Language is used to parse the given representation of date and time with the given template.

Syntax: strptime(x, format, tz = “”)

Parameters:
x: given representation of date and time
y: given template in which parsing is done
tz: a character string specifying the time zone to be used for the conversion

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strptime function
  
# Specifing a time
x <- "13:15:17"
  
# Calling strptime() function 
# over specified time and template
y <- strptime(x, "% H:% M:% S")
  
# Getting the current date and 
# given time into specified template
y

chevron_right


Output:

[1] "2020-06-17 13:15:17 UTC"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# strptime function
  
# Specifing a date and time
x <- "10-02-2020 05:05:06 AM"
  
# Calling strptime() function 
# over specified date and time, template
# and time zone
y <- strptime(x, "% d-% m-% Y % I:% M:% S", "GMT")
  
# Getting parsed date and time
y

chevron_right


Output:

[1] "2020-02-10 05:05:06 GMT"
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.