Is there a fast, low-garbage way to do it? I can’t just do simple modulus arithmetic since that doesn’t account for leap seconds and other date/time funny business.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is a fast, zero-garbage solution. It is of key importance not to create a new instance of
Calendaron each call because it’s quite a heavyweight object, taking 448 bytes of heap and almost a microsecond to initialize (Java 6, 64-bit HotSpot, OS X).HmsCalculatoris intended for use from a single thread (each thread must use a different instance).P.S. I didn’t paste all those static imports (boring).