R 程序:创建系统当前日期(带和不带时间)


2023年2月5日, Learn eTutorial
1360

如何查找系统的当前日期(带和不带时间)

在此,我们将解释如何编写 R 程序来查找系统的当前日期(带和不带时间)。为此,我们使用内置函数 Sys.Date() Sys.time()

  • Sys.Date() 函数将返回系统日期。我们不需要在此函数括号内添加任何参数。
  • Sys.time() 函数将返回系统当前日期和时间以及时区详细信息。

还有一个函数是

  • Sys.timezone(),它允许我们根据用户在系统上运行代码的位置来获取时区。

在此 R 程序中,此内置函数不需要任何参数。Sys.time() 函数将返回系统当前日期和时间,而 Sys.Date() 函数将仅返回系统日期。

算法

步骤 1:调用 Sys.Date() 只打印当前系统日期

步骤 2:打印函数结果

步骤 3:调用 Sys.time() 打印当前系统日期和时区

步骤 4:打印带时间的函数结果

R 源代码

                                          print("System's idea of the current date without time:")
print(Sys.Date())
print("System's idea of the current date with time:")
print(Sys.time())
                                      

输出

[1] "System's idea of the current date without time:"
[1] "2021-08-05"
[1] "System's idea of the current date with time:"
[1] "2021-08-05 17:06:00 UTC"