That's a very vague question - you might get a more useful answer if you tell us what you actually need to do, rather than start with the "how".
As a generalised answer though, I'd say "write an add on" - start at https://developer.atlassian.com/display/CONFDEV/Writing+Confluence+Plugins where you'll find you can write whatever you want, as classes, include your own libraries and make direct use of the internals of Confluence.
Ok, that's replacing stuff, rather than adding, which is a little more complex. I don't believe plugins can simply replace classes in the core of Confluence, and I don't believe they can subvert and override existing classes either. Via a plugin, they can extend and reuse, but that doesn't mean you can modify existing stuff.
I've got four basic approaches, using the dateformatter example you've given:
For (2), you need to read the log file for the errors. As you are replacing classes, you need to make sure that your new classes implement the same functions as the existing classes, at the very least for all of the calls Confluence makes. With date functions that could get quite messy because there's quite a lot there, and you'll have to replace all the input and output. I'd generally only recommend this approach for small, minor changes that don't actually change much (the only time I've personally used it was to enable the use of fractions in Jira's time-tracking field, which was minor because it was simply more clever parsing of input)
For (1), I already said - you would need to modify the .vm files that format dates so that they use your classes instead of the built-in ones.
Hey there Community! My name is Vannya Vallejo, the Channel Communication Specialist at Atlassian and I want to help Atlassian users like you learn about our Solution Partners and how they c...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs