Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ISO 8601中的时区_R_String_Datetime_Iso8601 - Fatal编程技术网

R 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

当使用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

作为变体,可以使用这种方式:

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