日期导入,不正确的世纪

时间:2012-08-01 23:29:07

标签: r date

我有一堆我正在解析的日期,格式为“%m /%d /%y”。 as.Date(dates, format = "%m/%d/%y")将“1/01/64”之类的日期转换为“2064-01-01”,但我需要将其作为“1964-01-01”。我想我可以找到未来一年的情况,然后减去一个世纪,但这似乎有点荒谬。

2 个答案:

答案 0 :(得分:3)

日期内部存储为整数天,因此输入或输出时只有这种格式。至于没有世纪信息的输入,我认为你运气不好。这是什么?strptime谈到%y格式规范:“在输入时,值00到68的前缀是20和69到99乘19 - 这是2004和2008 POSIX标准规定的行为,但他们也说'预计在未来版本中,从2位数年份推断的默认世纪将改变“。”

  as.Date( "01/01/64", "%m/%d/%y", origin="1970-01-01") -100*365.25
  #[1] "1964-01-01"

考虑到Y2K过去是如此新近,有可能开始对那些允许删除世纪信息的程序员进行酒吧斗争。

由于默认假设年份00-68是2000-2068,因此当然可以创建as.Dateshift

答案 1 :(得分:0)

修复日期的另一种方法是将未来发生的所有年份(相对于今天使用Sys.Date()的日期)更改为19而不是20。

org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-NO00B13', ip: '192.168.100.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: PhantomJSDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
    at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:116)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:105)
    at js.scrapertool.webpages.LinkedIn.initDriver(LinkedIn.java:258)
    at js.scrapertool.webpages.LinkedIn.login(LinkedIn.java:39)
    at js.scrapertool.main.Main.login(Main.java:47)
    at js.scrapertool.gui.windows.Login$4.doInBackground(Login.java:151)
    at js.scrapertool.gui.windows.Login$4.doInBackground(Login.java:1)
    at javax.swing.SwingWorker$1.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at javax.swing.SwingWorker.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:14791/status] to be available after 20002 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:107)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:190)
    ... 19 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:140)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)
    ... 20 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:128)
    ... 21 more