R语言 获得给定日期和时间对象的字符串表示 – strftime() 函数

R语言 获得给定日期和时间对象的字符串表示 – strftime() 函数

R语言中的 strftime() 函数用于将给定的日期和时间对象转换为其字符串表示。

语法: strftime(time)

参数:

time: 指定的时间对象

例子1:

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

输出:

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

例2:

# R program to illustrate
# strftime function
 
# Specifying 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
R

输出:

[1] "2020-06-17"
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册