在R中进行POSIXlt转换期间删除时区 [英] Remove timezone during POSIXlt Conversion in R

查看:100
本文介绍了在R中进行POSIXlt转换期间删除时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据框中有一个列,作为日期时间(因子),其值为 15-10-2017 16:41:00。

I have a column in my dataframe as datetime (factor) with the values as "15-10-2017 16:41:00".

我想要这个数据将被转换为 2017-10-15 16:41:00。
当我尝试转换时,我也将时区作为输出。

I wanted this data to be converted as "2017-10-15 16:41:00". When i try to convert this, I'm getting the timezone also as output.

我尝试使用tz =,usetz = F,但没有用。
任何建议吗?

I tried using tz="", usetz=F but no use. Any suggestions ?

代码:


as.POSIXlt( 15-10-2017 16:41:00,格式=%d-%m-%Y%H:%M:%S)
[1] 2017-10-15 16:41 :00 IST

as.POSIXlt("15-10-2017 16:41:00",format = "%d-%m-%Y %H:%M:%S") [1] "2017-10-15 16:41:00 IST"


推荐答案

as的帮助页面中。 POSIXlt

是当前时区

这是默认设置。

这就是为什么它不起作用的原因。您可以通过这种方式删除时区信息,并且在打印时不会显示该信息:

That's why it does not work. You could remove the timezone information this way, and it will not show while printing:

my_datetime <- as.POSIXlt("15-10-2017 16:41:00",format = "%d-%m-%Y %H:%M:%S")
my_datetime$zone <- NULL
my_datetime

但我不明白您为什么要这么做。如果您不想担心时区,则应转换为GMT。另外,如果必须强制某些特定时区, lubridate 软件包还具有不错的 force_tz 函数。

but I don't understand why you would want to do that. You should convert to GMT if you don't want to worry about the timezone. Also lubridate package has a nice force_tz function if you have to force some specific timezones.

这篇关于在R中进行POSIXlt转换期间删除时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆