An occupation time formula for semimartingales in RN