No, it's not possible to have java code within liferay theme.
You already have dateUtil
reference within velocity context to have some date utilities. Refer to DateUtil_IW
class for method list.
Inject new util class in velocity it's quite complex to explain, you have to build an ext plugin. It's better to build a portlet plugin and embed it within theme.