This was a short novel (maybe YA?) that I read back in the 80's or 90's. I'm pretty sure it was part of a series.
Legend has it that there's a pirate treasure buried on the beach just outside of town. Unfortunately, the coastline has shifted in the centuries since it was buried, and now, whenever someone tries to dig it up, the tide comes in before they reach the treasure and washes away their work. So, the protagonists get the idea to use their time machine* to go back to a time when it was possible to reach the treasure, and dig it up then.
But, they don't quite think their plan through all the way. They just go back to the day the treasure was buried... you know, the one day that the original pirates are guaranteed to still be around. Pirates that are not too happy that some random strangers in weird clothes are hanging around where they just finished burying their treasure.
There are two things that I specifically remember:
One is that some of the time travelers are tied to a tree and left to die of thirst, while the rest are taken to be sold as slaves. It takes over a day for the slaves-to-be to come up with a reason for the pirates to go back (I can't remember what that reason was).
The second is that the pirate captain found their time machine, and accidentally activated it. The time-travelers talk about the time machine like it's a stick-shift vehicle; since it's in neutral, it's not going to go any
wherewhen, so its main monitor should still be showing the beach. They convince the rest of the pirates to let them write a magic spell on a spare piece of sail to bring back their captain. The "spell" is actually instructions on how to work the time machine, and since the captain is the only literate person among the pirates, he can read and follow the instructions.
*This is the part that has me convinced that the book is part of a series. There's absolutely no explanation of why the protagonists have a flipping time machine; they just do. It's almost as if the author expected the reader to already know about it.