来自 ISO 8601 的时区
Time zone from ISO 8601
当有像这样的 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(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
当有像这样的 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(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