r - 为什么 R 的 strftime 会返回上个月的午夜?
问题描述
这正好在边缘,是一个病态的案例,但它给我带来了麻烦:
> strftime(as.POSIXct('2016-07-01', tz = 'UTC'), '%m')
[1] "06"
好像应该是 7 点,虽然我知道现在是午夜。这些是7:
> strftime(as.POSIXct('2016-07-02', tz = 'UTC'), '%m')
[1] "07"
> strftime(as.POSIXct('2016-07-01'), '%m')
[1] "07"
这里发生了什么?
解决方案
将时区添加到strftime
:
strftime(as.POSIXct('2016-07-01', tz = 'UTC'), '%m', tz="UTC")
[1] "07"
解释:
您只为as.POSIXct
. 然后您在strftime
不指定时区的情况下使用,这会导致strftime
回退到其默认值
来自?strftime
:
tz一个字符串,指定用于转换的时区。系统特定(参见 as.POSIXlt)
如果您的系统时区不是UTC
,则可能会导致这种差异。
推荐阅读
- smpp - Java.io.IOException: 使用openSMPP lib发送短信时会报未连接
- excel - VBA代码根据动态更新的单元格值删除行
- django - 如何在特定时间段后超时连接,比如 15 秒结束
- jsf - 如何将 Primefaces Tree 组件的叶子制作为 Commandlink
- java - 如何创建属性以定义具有通用前缀的不同模式名称?
- c# - 我如何以编程方式查找文件中的公共行并将它们写入新文件 c#
- ios - 如何在 SwiftUI 的标题栏上添加项目?
- c++ - OpenSSL TLS 服务器 - 使用客户端证书白名单
- python - 如何从另一个目录导入 python 类
- plsql - utl_smtp 如何处理来自错误电子邮件地址的拒绝电子邮件