Retrieve System Date and Time in R
Write a R program to create the system's idea of the current date with and without time.
Sample Solution :
R Programming Code :
# Print a message indicating the system's idea of the current date with and without time
print("System's idea of the current date with and without time:")
# Print the current date (without time) according to the system
print(Sys.Date())
# Print the current date and time according to the system
print(Sys.time())
Output:
[1] "System's idea of the current date with and without time:" [1] "2018-11-13" [1] "2018-11-13 12:33:23 UTC"
Explanation:
- Prints a descriptive message:
- print("System's idea of the current date with and without time:")
- Displays a string indicating that the following output will show the current date and time.
- Prints the current date:
- print(Sys.Date())
- Sys.Date() retrieves and prints the current system date in the format "YYYY-MM-DD".
- Prints the current date and time:
- print(Sys.time())
- Sys.time() retrieves and prints the current system date and time, including hours, minutes, and seconds, in the format "YYYY-MM-DD HH:MM
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics