Oil gained after President Donald Trump gave Iran an ultimatum to reopen the Strait of Hormuz and Tehran threatened reprisals.