title: How can I parse timestamps with +13:00 offset in R?
body: <p>I need to parse characters in ISO8601 with R. The format for the characters is the following:</p>
  
  <p><code>%Y-%m-%dT%H:%M:%S%z</code></p>
  
  <p>One example that causes problems is the following:</p>
  
  <p><code>2000-01-02T13:00:00.000+13:00</code></p>
  
  <p>I am able to remove the <code>:</code> in the UTC offset, but this results in nothing useful.</p>
  
  <p>I am using rstudio 1.2.1335 running in a docker container build from rocker/geospatial:latest via this <a href="https://github.com/EHJ-52n/sos4R/blob/feature/0.4/docker/Dockerfile" rel="nofollow noreferrer">Dockerfile</a>. The environment of R is:</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.6.0 (2019-04-26)
  Platform: x86_64-pc-linux-gnu (64-bit)
  Running under: Debian GNU/Linux 9 (stretch)
  
  Matrix products: default
  BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
  
  locale:
   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
   [6] LC_MESSAGES=C              LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
  [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] parsedate_1.2.0  sos4R_0.4.0.9002 stringr_1.4.0    httr_1.4.0       webmockr_0.3.4   testthat_2.1.1  
  
  loaded via a namespace (and not attached):
   [1] Rcpp_1.0.1         compiler_3.6.0     pillar_1.4.0       remotes_2.0.4      prettyunits_1.0.2  tools_3.6.0        digest_0.6.18     
   [8] packrat_0.5.0      pkgbuild_1.0.3     uuid_0.1-2         pkgload_1.0.2      memoise_1.1.0      tibble_2.1.1       lattice_0.20-38   
  [15] anytime_0.3.3      pkgconfig_2.0.2    rlang_0.3.4        cli_1.1.0          rstudioapi_0.10    withr_2.1.2        xml2_1.2.0        
  [22] fs_1.3.1           fauxpas_0.2.0      desc_1.2.0         devtools_2.0.2     rprojroot_1.3-2    grid_3.6.0         glue_1.3.1        
  [29] R6_2.4.0           processx_3.3.1     sessioninfo_1.1.1  sp_1.3-1           callr_3.2.0        magrittr_1.5       rematch2_2.0.1    
  [36] usethis_1.5.0      ps_1.3.0           backports_1.1.4    assertthat_0.2.1   RApiDatetime_0.0.4 stringi_1.4.3      crayon_1.3.4
  </code></pre>
  
  <p>I tried using <code>lubridate</code>, <code>parsedate</code>, <code>anytime</code> but none of them seem to be able to parse the timezone correctly.</p>
  
  <p>In the end, I tried the solution presented <a href="https://stackoverflow.com/a/15838721">here at stack overflow</a> with the following result:</p>
  
  <pre><code>&gt; timestring &lt;- "2000-01-02T13:00:00.000+13:00"
  &gt; fmt &lt;- "%Y-%m-%dT%H:%M:%S%z"
  &gt; cleanedTimestring &lt;- gsub("(.*).(..)$","\\1\\2",timestring)
  &gt; parsedTime &lt;- strptime(cleanedTimestring, fmt, tz = "UTC")
  &gt; str(parsedTime)
   POSIXlt[1:1], format: NA
  </code></pre>
  
  <p>When changing the UTC offset to <code>12:00</code> and removing the milliseconds <code>.000</code>, a nearly useful result is created:</p>
  
  <pre><code>&gt; timestring &lt;- "2000-01-02T13:00:00+12:00"
  &gt; cleanedTimestring &lt;- gsub("(.*).(..)$","\\1\\2",timestring)
  &gt; parsedTime &lt;- strptime(cleanedTimestring, fmt, tz = "UTC")
  &gt; str(parsedTime)
   POSIXlt[1:1], format: "2000-01-02 01:00:00"
  &gt; parsedTime
  [1] "2000-01-02 01:00:00 UTC"
  </code></pre>
  
  <p>But this is too much preprocessing and I am loosing information because of the missing milliseconds.</p>
  
  <p>I expect to be able to parse a string like <code>2000-01-02T13:00:00.000+13:00</code> to a <code>POSIXct</code> that results in the following:</p>
  
  <pre><code>[1] "2000-01-02 13:00:00.000 NZDT"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>[1] "2000-01-02T13:00:00.000+13:00"
  </code></pre>
  
  <p>Is there any lib that is able to do this?</p>
  
  <p>Remember, that I do not know beforehand the timezone of the timestamps. They might come as UTC offsets or id (e.g. <code>+13:00|+1300</code> vs. <code>NZDT</code>.</p>
  
  <p>Do you need any additional details?</p>