Sometimes if the bones are pretty badly broken up it's hard to tell what animal they belonged to. Usually you can tell pretty well what kind of dinosaur made them, at least to the level of what family or group of species. But you need a bone that is diagnostic, which means you can tell by its shape alone what animal uniquely had it, to be able to figure what animal produced the fossil. You tell the rock's age by small fossils of plants and little animals that we already know the age of, or by chemical testing if it is volcanic rock. Sometimes we can tell the age of the rock and the fossils in it within 100,000 years of the actual time, even if it happened 300 million years ago.
Volcanic rock contains some radioactive minerals in tiny amounts.
These minerals break down over time at a very steady rate. By measuring how much of these minerals have broken down we can date such a volcanic rock to within 100,000 years of when it was made, even if it was many millions of years ago. Of course, such volcanic rock isn't always around dinosaur fossils. So often we have to guess from these other clues. The first dinosaur discovered and named was iguanodon in the 1820's in England, from a tooth brought to a medical doctor named Gideon Mantell.