简体   繁体   中英

Why does strptime always return NA?

retest = c("May 31 2014 07:31:46", "May 31 2014 07:32:24", "May 31 2014 07:32:24",
           "May 31 2014 07:32:26", "May 31 2014 07:32:33", "May 31 2014 07:32:38",
           "May 31 2014 07:32:44", "May 31 2014 07:32:49", "May 31 2014 07:32:52",
           "May 31 2014 07:32:53")

a <- strptime(retest, format="%B %d %Y %H:%M:%S")
a
# [1] NA NA NA NA NA NA NA NA NA NA

What am I missing?

You need to change the locale :

# backup original locale
bkp <- Sys.getlocale('LC_TIME')

# change locale
Sys.setlocale('LC_TIME','C')

retest = c("May 31 2014 07:31:46", "May 31 2014 07:32:24", "May 31 2014 07:32:24",
          "May 31 2014 07:32:26", "May 31 2014 07:32:33", "May 31 2014 07:32:38",
          "May 31 2014 07:32:44", "May 31 2014 07:32:49", "May 31 2014 07:32:52",
          "May 31 2014 07:32:53")

a <- strptime(retest, format="%B %d %Y %H:%M:%S")

# restore original locale (if you want...)
Sys.setlocale('LC_TIME',bkp)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM