Setting the timezone
If you import a datetime and it has the wrong timezone, you can set it with force_tz()
. Pass in the datetime as the first argument and the appropriate timezone to the tzone
argument. Remember the timezone needs to be one from OlsonNames()
.
I wanted to watch New Zealand in the Women's World Cup Soccer games in 2015, but the times listed on the FIFA website were all in times local to the venues. In this exercise you'll help me set the timezones, then in the next exercise you'll help me figure out what time I needed to tune in to watch them.
Este exercício faz parte do curso
Working with Dates and Times in R
Instruções do exercício
I've put the times as listed on the FIFA website for games 2 and 3 in the group stage for New Zealand in your code.
- Game 2 was played in Edmonton. Use
force_tz()
to set the timezone of game 2 to"America/Edmonton"
. - Game 3 was played in Winnipeg. Use
force_tz()
to set the timezone of game 3 to"America/Winnipeg"
. - Find out how long the team had to rest between the two games, by using
as.period()
on the interval betweengame2_local
andgame3_local
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Game2: CAN vs NZL in Edmonton
game2 <- mdy_hm("June 11 2015 19:00")
# Game3: CHN vs NZL in Winnipeg
game3 <- mdy_hm("June 15 2015 18:30")
# Set the timezone to "America/Edmonton"
game2_local <- ___(game2, tzone = ___)
game2_local
# Set the timezone to "America/Winnipeg"
game3_local <- ___(game3, tzone = ___)
game3_local
# How long does the team have to rest?
as.period(___)