R lubridate:为什么我会收到“未知时区”错误?

时间:2022-08-22 23:18:11

Why is it I get an "unknown timezone" error when I am trying to use the mdy function?

当我尝试使用mdy函数时,为什么会出现“未知时区”错误?

> library(lubridate)

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

    date

> mdy('15-01-2018')
Error in as.POSIXlt.POSIXct(x, tz) : 
  (converted from warning) unknown timezone 'zone/tz/2017c.1.0/zoneinfo/Asia/Hong_Kong'

1 个解决方案

#1


2  

As suggested by Matt Gibson and Roland, the error has to do with running an older version of R.

正如Matt Gibson和Roland所建议的那样,错误与运行旧版本的R有关。

I had installed R version 3.4.1 around August 2017, when my computer was running macOS 10.12 Sierra. Around November 2017, I had updated macOS to 10.13 High Sierra. After I installed R version 3.4.3, the unknown timezone error no longer appeared.

我在2017年8月左右安装了R版本3.4.1,当时我的计算机运行的是macOS 10.12 Sierra。 2017年11月左右,我将macOS更新为10.13 High Sierra。安装R版本3.4.3后,不再出现未知时区错误。

> library(lubridate)

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

    date

> mdy('15-01-2018')
[1] NA
Warning message:
All formats failed to parse. No formats found. 

Of course, the format fails to parse, because as Prem and InfiniteFlashChess mentioned, I had mixed up the month and date in the mdy function.

当然,格式无法解析,因为正如Prem和InfiniteFlashChess所提到的,我在mdy函数中混淆了月份和日期。

> mdy('01-15-2018')
[1] "2018-01-15"

#1


2  

As suggested by Matt Gibson and Roland, the error has to do with running an older version of R.

正如Matt Gibson和Roland所建议的那样,错误与运行旧版本的R有关。

I had installed R version 3.4.1 around August 2017, when my computer was running macOS 10.12 Sierra. Around November 2017, I had updated macOS to 10.13 High Sierra. After I installed R version 3.4.3, the unknown timezone error no longer appeared.

我在2017年8月左右安装了R版本3.4.1,当时我的计算机运行的是macOS 10.12 Sierra。 2017年11月左右,我将macOS更新为10.13 High Sierra。安装R版本3.4.3后,不再出现未知时区错误。

> library(lubridate)

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

    date

> mdy('15-01-2018')
[1] NA
Warning message:
All formats failed to parse. No formats found. 

Of course, the format fails to parse, because as Prem and InfiniteFlashChess mentioned, I had mixed up the month and date in the mdy function.

当然,格式无法解析,因为正如Prem和InfiniteFlashChess所提到的,我在mdy函数中混淆了月份和日期。

> mdy('01-15-2018')
[1] "2018-01-15"