VOOZH about

URL: https://www.geeksforgeeks.org/r-language/how-to-convert-character-to-a-timestamp-in-r/

⇱ How to Convert Character to a Timestamp in R? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Convert Character to a Timestamp in R?

Last Updated : 28 Dec, 2021

In this article, we will convert character to timestamp in R Programming Language.

We can convert the character to timestamp by using strptime() method. strptime() function in R Language is used to parse the given representation of date and time with the given template.

Syntax

strptime(character, format, tz = “”)

Where,  

  • character: given representation of date and time   in string format
  • tz: a character string specifying the time zone to be used for the conversion

Example 1: Convert character to year , month and date format timestamp

Output:

[1] "2021-04-04 UTC"

Example 2: R program to convert character into timestamp

Output:

[1] "2021-04-04 02:23:34 UTC"

Example 3: In this example, we are going to specify the timezone

Output:

[1] "2021-04-04 02:23:34 UTC"
Comment
Article Tags:

Explore