localdate

DateTimeParseException: Text could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor

拥有回忆 提交于 2020-05-10 09:55:24
问题 LocalDateTime.parse("2017-02-02 08:59:12", DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")); It prints error: java.time.format.DateTimeParseException: Text '2017-02-02 08:59:12' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {MinuteOfHour=59, NanoOfSecond=0, SecondOfMinute=12, MicroOfSecond=0, MilliOfSecond=0, HourOfAmPm=8},ISO resolved to 2017-02-02 of type java.time.format.Parsed Accoeding message looks like all values parsed correct, but anyway I see error.

final static LocalDateTime retrieving from another class is throwing java.lang.ExceptionInInitializerError

柔情痞子 提交于 2020-04-30 14:26:31
问题 I have a variable MINDATE in MyConstants file. You can see the declaration below. public static final LocalDateTime MINDATE = LocalDateTime.of(LocalDate.of(2011, 1, 1), LocalTime.MIDNIGHT); I am consuming this variable in another class just by using MyConstants.MINDATE then I get the following exception Exception in thread "main" java.lang.ExceptionInInitializerError at com.cw.na.vos.DateTest.main(DateTest.java:14) Caused by: java.lang.IllegalArgumentException: Unknown pattern letter: T at

final static LocalDateTime retrieving from another class is throwing java.lang.ExceptionInInitializerError

扶醉桌前 提交于 2020-04-30 14:24:12
问题 I have a variable MINDATE in MyConstants file. You can see the declaration below. public static final LocalDateTime MINDATE = LocalDateTime.of(LocalDate.of(2011, 1, 1), LocalTime.MIDNIGHT); I am consuming this variable in another class just by using MyConstants.MINDATE then I get the following exception Exception in thread "main" java.lang.ExceptionInInitializerError at com.cw.na.vos.DateTest.main(DateTest.java:14) Caused by: java.lang.IllegalArgumentException: Unknown pattern letter: T at

final static LocalDateTime retrieving from another class is throwing java.lang.ExceptionInInitializerError

烈酒焚心 提交于 2020-04-30 14:21:55
问题 I have a variable MINDATE in MyConstants file. You can see the declaration below. public static final LocalDateTime MINDATE = LocalDateTime.of(LocalDate.of(2011, 1, 1), LocalTime.MIDNIGHT); I am consuming this variable in another class just by using MyConstants.MINDATE then I get the following exception Exception in thread "main" java.lang.ExceptionInInitializerError at com.cw.na.vos.DateTest.main(DateTest.java:14) Caused by: java.lang.IllegalArgumentException: Unknown pattern letter: T at

Deserialize date attribute of json into LocalDate

可紊 提交于 2020-04-29 12:50:51
问题 I am trying to de-serialize date attribute in json of format "2018-05-27" using Gson. I want date to be in LocalDate format after de-serialization. For json input : { "id" : 1, "name" : "test", "startDate" : "2018-01-01", "endDate" : "2018-01-05", } I am getting error for startDate and endDate : java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING 回答1: The way we can do this is : private static final Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new

How to stop LocalDate from changing when being saved to a mySQL database

百般思念 提交于 2020-02-21 09:49:53
问题 When saving a LocalDate field (e.g. '2017-09-27') to a mySQL Date column using JPA CriteriaBuilder API, the result is different (e.g. '2017-09-26'). I have validated that my database's timezone is set to UTC using SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) as the result is '00:00:00'. I am testing this locally, and I have a timezone of GMT + 2, so my suspicion is that when the conversion occurs from LocalDate to Date , 2 hours are being deducted and producing a date 1 day before the requested date

How to stop LocalDate from changing when being saved to a mySQL database

可紊 提交于 2020-02-21 09:48:52
问题 When saving a LocalDate field (e.g. '2017-09-27') to a mySQL Date column using JPA CriteriaBuilder API, the result is different (e.g. '2017-09-26'). I have validated that my database's timezone is set to UTC using SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) as the result is '00:00:00'. I am testing this locally, and I have a timezone of GMT + 2, so my suspicion is that when the conversion occurs from LocalDate to Date , 2 hours are being deducted and producing a date 1 day before the requested date

How to stop LocalDate from changing when being saved to a mySQL database

眉间皱痕 提交于 2020-02-21 09:48:26
问题 When saving a LocalDate field (e.g. '2017-09-27') to a mySQL Date column using JPA CriteriaBuilder API, the result is different (e.g. '2017-09-26'). I have validated that my database's timezone is set to UTC using SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) as the result is '00:00:00'. I am testing this locally, and I have a timezone of GMT + 2, so my suspicion is that when the conversion occurs from LocalDate to Date , 2 hours are being deducted and producing a date 1 day before the requested date

Parsing timestamp as LocalDateTime

孤者浪人 提交于 2020-01-30 13:09:11
问题 I want to parse a timestamp in the form of yyyy-MM-dd'T'HH:mm:ss as LocalDateTime . When doing so, it strips the seconds if they are 00 . As described here, I need to use a custom formatter LocalDateTime date = LocalDateTime.parse("2008-10-02T12:30:00"); DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); String dateString = date.toString(); String dateFormatted = date.format(f); System.out.println(dateString); // 2008-10-02T12:30 This one works, but it returns a

LocalDate comparison, getting orders between two dates

China☆狼群 提交于 2020-01-25 07:13:05
问题 public List<WorkItem> getWorkItemsByDate(String startDate, String endDate) throws ParseException { LocalDate parsedStartDate = LocalDate.parse(startDate); LocalDate parsedEndDate = LocalDate.parse(endDate); return workItemRepository.findAll().stream().filter(w -> w.getUpdateDate().isAfter(parsedStartDate) && w.getUpdateDate().isBefore(parsedEndDate)) .collect(Collectors.toList()); } I have two dates that I want to compare between and find all the workitems(has LocalDate) for the dates. I have