R ISO 8601中的时区
当使用ISO 8601格式的时间字符串时,如下所示:R ISO 8601中的时区,r,string,datetime,iso8601,R,String,Datetime,Iso8601,当使用ISO 8601格式的时间字符串时,如下所示: "2016-07-04T17:00:00+02:00" 如何从R中获取时区作为数字向量?作为变量,可以使用以下方法: getTimeZone = function(time) { last = substring(time, nchar(time), nchar(time)); if(last == 'Z') { return(0); } else { mins = as.numeric(substr
"2016-07-04T17:00:00+02:00"
如何从R中获取时区作为数字向量?作为变量,可以使用以下方法:
getTimeZone = function(time)
{
last = substring(time, nchar(time), nchar(time));
if(last == 'Z')
{
return(0);
}
else
{
mins = as.numeric(substring(time, nchar(time)-1, nchar(time)));
hours = as.numeric(substring(time, nchar(time)-4, nchar(time)-3));
timezone = hours + mins/60;
}
}
现在,当执行此操作时:
a = getTimeZone("2016-07-04T12:00:00Z")
b = getTimeZone("2016-07-04T12:00:00+02:30")
a
b
我们下一步:
[1] 0
[1] 2.5
作为变体,可以使用这种方式:
getTimeZone = function(time)
{
last = substring(time, nchar(time), nchar(time));
if(last == 'Z')
{
return(0);
}
else
{
mins = as.numeric(substring(time, nchar(time)-1, nchar(time)));
hours = as.numeric(substring(time, nchar(time)-4, nchar(time)-3));
timezone = hours + mins/60;
}
}
现在,当执行此操作时:
a = getTimeZone("2016-07-04T12:00:00Z")
b = getTimeZone("2016-07-04T12:00:00+02:30")
a
b
我们下一步:
[1] 0
[1] 2.5