DougBreaux 270007SMYJ Visits (5103)
Follow up to previous post, New
Variable fraction digits
It turns out (I should have read the Stac
After some wrestling and initial despair, the following actually seems to fully handle that, using the longer, more controlled form of creating a Formatter via a "Builder":
public static final DateTimeFormatter TZ_FORMATTER =
Which is 0-3 digits of milliseconds, with "true" for the decimal point.
Note that I also switched the pattern to use single-character Month, day, Hours, minutes, seconds. Learned too that using 2-digit then requires 2 digits always. Unlike java
Quick info about my foray into new java.time classes, because they offer the
Which we wanted because apparently the C# .NET code that one of our customers uses will
But moving to these new classes wasn't as simple (for me) as I had expected, so I wanted to document what ended up working for me, I admit through a combination of StackOverflow and trial-and-error. And possibly even revealing my ignorance of a better approach...
In this case, our code still wants a java.sql.Timestamp field, in the JVM's Time-zone (which we usually set to UTC), from a "string" date/time field that is in the customer's (Arizona) Time Zone. There may have been an easier way if we could use something other than java.sql.Timestamp, but I was trying to impact as little code as possible.
Here's the relevant code:
// unlike SimpleDateFormat, DateTimeFormatter instance is thread-safe, so can share one