當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R語言 strftime()用法及代碼示例

R 語言中的 strftime() 函數用於將給定的日期和時間對象轉換為其字符串表示形式。

用法: strftime(time) 
參數: 
time: specified time object
 

範例1:

Python3


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

輸出:



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

範例2:

Python3


# 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

輸出:

[1] "2020-06-17"

相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Getting String Representation of the given Date and Time Object in R Programming – strftime() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。