Java SE 8 TemporalAccessor.from issues when used with a java.time.Instant object

Short answer: The JSR-310-designers don’t want people to do conversions between machine time and human time via static from()-methods in types like ZoneId, ZoneOffset, OffsetDateTime, ZonedDateTime etc. This is explicitly specified if you carefully study the javadoc. Instead use: OffsetDateTime#toInstant():Instant ZonedDateTime#toInstant():Instant Instant#atOffset(ZoneOffset):OffsetDateTime Instant#atZone(ZoneId):ZonedDateTime The problem with the static from()-methods is that otherwise people are able … Read more

Is java.time failing to parse fraction-of-second?

Bug – Fixed in Java 9 This issue was already reported in JDK-bug-log. Stephen Colebourne mentions as work-around following solution: DateTimeFormatter dtf = new DateTimeFormatterBuilder() .appendPattern(“yyyyMMddHHmmss”) .appendValue(ChronoField.MILLI_OF_SECOND, 3) .toFormatter(); Note: This workaround does not cover your use-case of only two pattern symbols SS. An adjustment might only be to use other fields like MICRO_OF_SECOND (6 … Read more

Kotlin Android / Java String DateTime Format, API21

Parse it to LocalDateTime then format it: LocalDateTime localDateTime = LocalDateTime.parse(“2018-12-14T09:55:00”); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“dd.MM.yyyy HH:mm”); String output = formatter.format(localDateTime); If this does not work with api21, you can use: SimpleDateFormat parser = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss”); SimpleDateFormat formatter = new SimpleDateFormat(“dd.MM.yyyy HH:mm”); String output = formatter.format(parser.parse(“2018-12-14T09:55:00”)); or import ThreeTenABP.

How to get localized short day-in-week name (Mo/Tu/We/Th…)

The best way is with java.text.DateFormatSymbols DateFormatSymbols symbols = new DateFormatSymbols(new Locale(“it”)); // for the current Locale : // DateFormatSymbols symbols = new DateFormatSymbols(); String[] dayNames = symbols.getShortWeekdays(); for (String s : dayNames) { System.out.print(s + ” “); } // output : dom lun mar mer gio ven sab

Convert between LocalDate and sql.Date [duplicate]

The Java 8 version (and later) of java.sql.Date has built in support for LocalDate, including toLocalDate and valueOf(LocalDate). To convert from LocalDate to java.sql.Date you can use java.sql.Date.valueOf( localDate ); And to convert from java.sql.Date to LocalDate: sqlDate.toLocalDate(); Time zones: The LocalDate type stores no time zone information, while java.sql.Date does. Therefore, when using the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)