📜  在 R 编程中解析日期和时间 – strptime()函数

📅  最后修改于: 2022-05-13 01:54:21.291000             🧑  作者: Mango

在 R 编程中解析日期和时间 – strptime()函数

R 语言中的strptime()函数用于使用给定模板解析给定的日期和时间表示。

示例 1:

Python3
# R program to illustrate
# strptime function
 
# Specifying a time
x <- "13:15:17"
 
# Calling strptime() function
# over specified time and template
y <- strptime(x, "% H:% M:% S")
 
# Getting the current date and
# given time into specified template
y


Python3
# R program to illustrate
# strptime function
 
# Specifying a date and time
x <- "10-02-2020 05:05:06 AM"
 
# Calling strptime() function
# over specified date and time, template
# and time zone
y <- strptime(x, "% d-% m-% Y % I:% M:% S", "GMT")
 
# Getting parsed date and time
y


输出:

[1] "2020-06-17 13:15:17 UTC"

示例 2:

Python3

# R program to illustrate
# strptime function
 
# Specifying a date and time
x <- "10-02-2020 05:05:06 AM"
 
# Calling strptime() function
# over specified date and time, template
# and time zone
y <- strptime(x, "% d-% m-% Y % I:% M:% S", "GMT")
 
# Getting parsed date and time
y

输出:

[1] "2020-02-10 05:05:06 GMT"