0

I am trying to convert "30 Jun 17 5:08 pm -0500" to POSIX time format in R.

date <- c("30 Jun 17 5:08 pm -0500")
mydate <- as.POSIXct(date, format="%d %b %y %I:%M %p %z")

The returned result is "2017-06-30 18:08:00 EDT".

Obviously, the time is incorrect, it should be 17:08:00.

Jian
  • 365
  • 1
  • 6
  • 19

1 Answers1

1

Your original time is from a -0500 timezone (5 hours behind UTC), which, assuming it was a standard US time zone, was likely Central Daylight Time, which has that offset. Your current timezone, Eastern Daylight Time, is -0400 (4 hours behind UTC).

In my case, since my computer is currently in CDT, I get the following result from your code:

mydate
## [1] "2017-06-30 17:08:00 CDT"

Which is as it should be, since my time zone matches the UTC offset that your time was originally from.

Nick Nimchuk
  • 386
  • 2
  • 11
  • Thank you, Nick. What a fortunate to have someone from CDT test the code for me. Haha. – Jian Aug 02 '17 at 18:04