用当前时间生成一个数据框,日期都能正常显示。
```{r}
date <- data.frame(
toDateString = c(Sys.time(), Sys.Date()),
toISOString = c(Sys.time(), Sys.Date()),
toLocaleDateString = c(Sys.time(), Sys.Date()),
toLocaleString = c(Sys.time(), Sys.Date()),
toLocaleTimeString = c(Sys.time(), Sys.Date()),
toString = c(Sys.time(), Sys.Date()),
toTimeString = c(Sys.time(), Sys.Date()),
toUTCString = c(Sys.time(), Sys.Date())
)
head(date)
```
toDateString toISOString toLocaleDateString toLocaleString toLocaleTimeString toString toTimeString
1 2022-10-09 21:45:53 2022-10-09 21:45:53 2022-10-09 21:45:53 2022-10-09 21:45:53 2022-10-09 21:45:53 2022-10-09 21:45:53 2022-10-09 21:45:53
2 2022-10-09 08:00:00 2022-10-09 08:00:00 2022-10-09 08:00:00 2022-10-09 08:00:00 2022-10-09 08:00:00 2022-10-09 08:00:00 2022-10-09 08:00:00
toUTCString
1 2022-10-09 21:45:53
2 2022-10-09 08:00:00
换作先生成矩阵,再转化成数据框,日期就变得很奇怪了。
```{r}
date <-
matrix(rep(c(Sys.time(), Sys.Date()), 8),
nrow = 2,
ncol = 8,
byrow = T)
date <- as.data.frame(date)
methods <- c(
'toDateString',
'toISOString',
'toLocaleDateString',
'toLocaleString',
'toLocaleTimeString',
'toString',
'toTimeString',
'toUTCString'
)
colnames(date) <- methods
head(date)
```
toDateString toISOString toLocaleDateString toLocaleString toLocaleTimeString toString toTimeString toUTCString
1 1665323289 1665273600 1665323289 1665273600 1665323289 1665273600 1665323289 1665273600
2 1665323289 1665273600 1665323289 1665273600 1665323289 1665273600 1665323289 1665273600
这是为撒呢?