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"
相關用法
- R語言 as.Date()用法及代碼示例
- R語言 strptime()用法及代碼示例
- R語言 table()用法及代碼示例
- R語言 toString()用法及代碼示例
- R語言 sapply()用法及代碼示例
- R語言 length()用法及代碼示例
- R語言 weekdays()用法及代碼示例
- R語言 months()用法及代碼示例
- R語言 quarters()用法及代碼示例
- R語言 get()用法及代碼示例
- R UNIX Timestamp轉Date Object用法及代碼示例
- R語言 determinant()用法及代碼示例
- R語言 charmatch()用法及代碼示例
- R語言 col()用法及代碼示例
- R語言 det()用法及代碼示例
- R語言 row()用法及代碼示例
- R語言 class()用法及代碼示例
- R語言 typeof()用法及代碼示例
- R語言 density()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Getting String Representation of the given Date and Time Object in R Programming – strftime() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。