java-time

DateTimeParse Exception

六眼飞鱼酱① 提交于 2021-02-04 08:41:05
问题 I am constantly getting an exception error in my code when parsing a date. The Date looks like this: Wed May 21 00:00:00 EDT 2008 This is the code for trying to read it: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy"); Property property = new Property(); property.setSale_date(LocalDateTime.parse(linesplit[8], formatter)); Expected result: A LocalDateTime of 2008-05-21T00:00 . What I got instead: Exception in thread "main" java.time.format

OffsetDateTime is not showing milisecond if the string contains 000 [duplicate]

你。 提交于 2021-01-29 08:52:23
问题 This question already has answers here : Convert JAXBElement<XMLGregorianCalendar> to OffsetDateTime (1 answer) Parsing timestamp as LocalDateTime (2 answers) Closed 7 months ago . I have a string "2020-03-25T22:00:00.000Z" which i want to convert to OffsetDateTime. Below is the code I tried but when I pass milisecond as 000 then it is not reflecting in OffsetDateTime. OffsetDateTime offsetDateTime=OffsetDateTime.parse("2020-03-25T22:00:01.123Z", DateTimeFormatter.ISO_OFFSET_DATE_TIME); print

How to process yyyy-mm and yyyy in java8 using DateTimeFormatter

社会主义新天地 提交于 2021-01-29 05:48:26
问题 Am using SimpleDateFormat to format or validate the dates, but I would like to make it thread-safe by using java 8 DateTimeFormatter. I am having trouble to achieve some requirement. My application will accept only three types of formats. "yyyy-MM-dd", "yyyy-MM", "yyyy" Existing Code gives me desired output: /*simple date format to process yyyy-MM-dd format SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd") /*simple date format to process yyyy-MM format SimpleDateFormat

Java 8 ISO 8601 Interval syntax with wildcard field(s)

无人久伴 提交于 2021-01-28 14:17:49
问题 I need to parse a time interval expression similar to ISO 8601 syntax, only allowing wildcard for fields; and storing the start and end into two LocalDateTime objects. My Interval would then have APIs to compare to a third LocalDateTime or OffsetDateTime to check if it falls inside or outside of the interval. E.g.: when parsing "****-**-**T00:00:00Z/****-**-**T11:55:00Z" , the date of the start and end instant should be the day of the start program execution (ignoring running into the next

JAVA - LocalDate.plusDay() doesn't work properly [duplicate]

社会主义新天地 提交于 2021-01-28 09:08:25
问题 This question already has answers here : Why LocalDate.plusDays not working here? (2 answers) Closed 2 years ago . I want to create method thatd add trainings which belongs to some trainingCycle to calendar. Problably I made some mistake becouse it's adding all trainings to only one day. TrainingCycle model class: @DynamoDBTable(tableName = "trainingCycle") public class TrainingCycle extends Request { private String id; private String cycleName; private Long cycleTime; private LocalDateTime

Call method at date/time

倖福魔咒の 提交于 2021-01-28 00:51:23
问题 I am searching for a modern way to execute a given method at a given date/time ( ZonedDateTime in particular). I am aware of the Timer class and the Quartz library, as shown here (the threads include full solutions): Java - Execute method on specific date [closed] Call a method at fixed time in Java But those threads are rather old and do not utilize the new Java features and library elements since then. In particular, it would be very handy to get hands on any kind of Future object, since

Where is the official list of zone names for java.time?

眉间皱痕 提交于 2021-01-26 06:05:56
问题 Is there an official list of zone names that are used for the following: zoneId = ZoneId.of("America/New_York") Or is it possible for java.time.ZoneId to generate the list itself that I can use? I'm using this to convert an Instant to a string representation of time like: ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("...")) 回答1: Just use the getAvailableZoneIds method. Gets the set of available zone IDs. This set includes the string form of all available region

Where is the official list of zone names for java.time?

独自空忆成欢 提交于 2021-01-26 06:04:15
问题 Is there an official list of zone names that are used for the following: zoneId = ZoneId.of("America/New_York") Or is it possible for java.time.ZoneId to generate the list itself that I can use? I'm using this to convert an Instant to a string representation of time like: ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("...")) 回答1: Just use the getAvailableZoneIds method. Gets the set of available zone IDs. This set includes the string form of all available region

Where is the official list of zone names for java.time?

╄→尐↘猪︶ㄣ 提交于 2021-01-26 06:04:14
问题 Is there an official list of zone names that are used for the following: zoneId = ZoneId.of("America/New_York") Or is it possible for java.time.ZoneId to generate the list itself that I can use? I'm using this to convert an Instant to a string representation of time like: ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("...")) 回答1: Just use the getAvailableZoneIds method. Gets the set of available zone IDs. This set includes the string form of all available region

Where is the official list of zone names for java.time?

∥☆過路亽.° 提交于 2021-01-26 06:03:37
问题 Is there an official list of zone names that are used for the following: zoneId = ZoneId.of("America/New_York") Or is it possible for java.time.ZoneId to generate the list itself that I can use? I'm using this to convert an Instant to a string representation of time like: ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("...")) 回答1: Just use the getAvailableZoneIds method. Gets the set of available zone IDs. This set includes the string form of all available region