Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Thursday, 10 September 2020

How to Tell Time in Java’s Garbage Collection

I found this interesting article1 on clock drifts and hardware clocks and OS clocks and Java and logging.

I really liked the quote in there:

“A person with a watch knows what time it is. A person with two watches is never sure.”
- Segal's Law

References

[1] How to Tell Time in Java’s Garbage Collection
https://devblogs.microsoft.com/java/how-to-tell-time-in-javas-garbage-collection/

Thursday, 2 January 2020

XMLGregorianCalendar off by a few days on dates before 1582

Oh, darn. Just got bit by this thing.

The customer had stored documents for which it did not know the date with date 01-01-0007.

When importing it via XML, it turned out wrong.

The reference [1] below explains why.

References

[1] StackOverflow - Date change when converting from XMLGregorianCalendar to Calendar
https://stackoverflow.com/questions/16321193/date-change-when-converting-from-xmlgregoriancalendar-to-calendar
Wikipedia - Proleptic Gregorian Calendar
https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar

Thursday, 31 October 2019

Freemarker and java.time

I noticed that Freemarker1 does not yet support the Java SE 8 Date and Time2. I noticed this, because I tried it. It just tries to parse the toString() and it fails.

There's already blogs about it.

So I had to add a little dependency to provide this, courtesy of Jakob Vad Nielsen3.

<dependency>
    <groupId>no.api.freemarker</groupId>
    <artifactId>freemarker-java8</artifactId>
    <version>1.1.5</version>
</dependency>

Of course, it's not native support, you still have to call specific methods to parse this. But it works in my case.

It means I have to change some of my templates around, as described below:

Published Date ${blog.createDate?datetime}
Instead should be:
Published Date ${blog.createDate.format()}

References

[1] FreeMarker Java Template Engine
https://freemarker.apache.org/
[2] Java Technical Details - Java SE 8 Date and Time
https://www.oracle.com/technical-resources/articles/java/jf14-date-time.html
[3] GitHUb - Java library adding support for the Java 8 java.time api to FreeMarker.
https://github.com/lazee/freemarker-java-8