Skip to content

Instantly share code, notes, and snippets.

@DavisVaughan
Created April 12, 2021 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavisVaughan/cbedcd5bcfcf9fedeafc3b1c36cfc5a8 to your computer and use it in GitHub Desktop.
Save DavisVaughan/cbedcd5bcfcf9fedeafc3b1c36cfc5a8 to your computer and use it in GitHub Desktop.
x <- lubridate::today()
x
#> [1] "2021-04-12"
# not what i wanted...
# (treats the Date as UTC, then shows it to you in your local tz)
as.POSIXct(x)
#> [1] "2021-04-11 20:00:00 EDT"
# probably what you wanted:
lubridate::force_tz(x, "America/New_York")
#> [1] "2021-04-12 EDT"
lubridate::force_tz(x, "Europe/London")
#> [1] "2021-04-12 BST"
@DavisVaughan
Copy link
Author

This would also be a great time to try clock 😝

x <- lubridate::today()
x
#> [1] "2021-04-12"

clock::as_date_time(x, "America/New_York")
#> [1] "2021-04-12 EDT"
clock::as_date_time(x, "Europe/London")
#> [1] "2021-04-12 BST"

Created on 2021-04-12 by the reprex package (v1.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment