java-time Questions

8

Solved

I have an external API that returns me dates as longs, represented as milliseconds since the beginning of the Epoch. With the old style Java API, I would simply construct a Date from it with Date...
Teplitz asked 3/2, 2016 at 16:58

3

I am trying to parse a ZonedDateTime from a String of the format (yyyy-MM-dd HH:mm z). The input String (2019-08-29 00:00 IST) generates a UTC timestamp. Debugging led me to a point where the Zon...
Rubble asked 30/8, 2019 at 22:35

4

Solved

I need to parse a field which is sometimes given as a date and sometimes as a date/time. Is it possible to use single datatype for this using Java 8 time API? Currently, I attempted to use a LocalD...
Roster asked 16/3, 2018 at 14:22

4

Solved

In Java, we can have many different ways to get the current timestamp, but which one is recommended: Instant.now().toEpochMilli() or System.currentTimeMillis()
Raft asked 5/11, 2019 at 6:31

10

Solved

I have an epoch second and a zoneId (see method1 below). It can be convert to LocalDateTime with system default zoneId, but I don't find the way to convert epoch second to LocalDateTime (see method...
Plotkin asked 17/9, 2015 at 9:21

6

Solved

I'm trying to convert a java.time.LocalTime object to java.util.Date but can't find any suitable method. What's the correct way to do this? Is there any reason why java doesn't seem to ship with a...
Christmas asked 13/10, 2015 at 9:11

13

I have a LocalDate which needs to get the first and last day of the month. How do I do that? eg. 13/2/2014 I need to get 1/2/2014 and 28/2/2014 in LocalDate formats. Using threeten LocalDate cla...
Gilliam asked 6/3, 2014 at 11:55

18

In Java how can I add one month to the current date?
Serene asked 5/2, 2011 at 6:4

6

I want to use java.time.LocalDate and java.time.LocalDateTime with an implicit Ordered like: val date1 = java.time.LocalDate.of(2000, 1, 1) val date2 = java.time.LocalDate.of(2010, 10, 10) if (dat...
Hypoglossal asked 27/6, 2016 at 16:46

3

I would like to convert instances of class java.time.Instant to and from Strings. I would like to use a format exactly like java.time.format.DateTimeFormatter.ISO_INSTANT with the only difference ...
Keyway asked 21/9, 2015 at 12:19

3

Solved

I'm migrating some signatures from f(long dur, TimeUnit timeUnit) to f(Duration duration), and would like to implement the former with the latter. Being on Java 8, I can't find any API to easily co...
Dennadennard asked 16/6, 2022 at 17:50

13

Solved

I want to convert java.time.LocalDate into java.util.Date type. Because I want to set the date into JDateChooser. Or is there any date chooser that supports java.time dates?
Eliaseliason asked 8/4, 2014 at 6:29

2

Solved

I have a problem with parsing ZonedDateTime: DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-ddzhh:mm"); ZonedDateTime.parse(s, formatter); This results in an error: java...

14

Solved

What is the best way to convert a java.util.Date object to the new JDK 8/JSR-310 java.time.LocalDate? Date input = new Date(); LocalDate date = ???
Dollop asked 20/1, 2014 at 19:6

4

Solved

I am using following ISO8601 format: YYYY-MM-DDThh:mm:ssZ And I used OffsetDateTime.parse() to parse this format. I was able to parse date-time by passing t (instead of T) and z (instead of Z) her...
Jahdai asked 1/12, 2020 at 8:20

3

Solved

In the following snipped the property $F is of class java.time.LocalDateTime or java.time.LocalDate. <textField pattern="EE. dd.MM.yyyy"> <reportElement...> </reportElement> &...
Stannic asked 8/8, 2016 at 13:38

4

Solved

I tried everything, but the error not getting solved Here is my code: public String[] getWeekDays() { LocalDate today = LocalDate.now(); LocalDate monday = today; LocalDate tue = today; Loca...
Yet asked 26/9, 2018 at 5:14

6

Solved

The java.util.Date class has a method called toInstant() that converts the Date instance to a java.time.Instant. The java.sql.Date class extends the java.util.Date class, but when I attempt to cal...
Xerophyte asked 5/4, 2016 at 19:35

8

Solved

Can I get localized short day-in-week name (Mo/Tu/We/Th/Fr/Sa/Su for English) in Java?
Ormand asked 24/9, 2010 at 21:1

3

Solved

Say I have a ZonedDateTime of 2018-10-30T18:04:58.874Z : How can I convert this to OffsetDateTime 2018-10-30T13:04:58.874-05:00 I'd prefer the offset to be the default/system offset, for example ...
Lita asked 30/10, 2018 at 19:35

3

Solved

The parser generated by DateTimeFormatter.ofPattern exhibits the following interesting behaviour which is preventing me from writing a pattern to parse a string like 20150100: System.out.println(D...
Helmholtz asked 25/8, 2016 at 16:10

4

I have two java.time.Instant objects Instant dt1; Instant dt2; I want to get time (only hours and minutes without date) from dt2 and set it to dt1. What is the best way to to this? Using dt2.get(C...
Unsparing asked 3/8, 2015 at 11:48

8

Solved

How to reduce one month from current date and want to sore in java.util.Date variable im using this code but it's shows error in 2nd line java.util.Date da = new Date(); da.add(Calendar.MONTH, -...
Dulosis asked 6/5, 2013 at 6:8

7

Java 8's DateTimeFormatter class has a method, ofPattern(String pattern), that lets you define a format from a string of A-z, a-z letters. The examples don't clarify the difference between y, year-...
Slosh asked 17/10, 2014 at 19:13

2

Solved

Is it possible to change the first day of week on JavaFX's DatePicker when applying Arabic locale? I need to change it from Saturday to Sunday.
Dagon asked 20/3, 2015 at 14:4

© 2022 - 2024 — McMap. All rights reserved.