336 questions
-2
votes
2
answers
258
views
Why does Java Date always display in system time zone instead of UTC?
I am working on a Java 8 application where I receive epoch millisecond timestamps that represent UTC time. I need to pass these timestamps as Date objects to a method that I do not control (from a ...
0
votes
0
answers
61
views
Postgres JDBC ignores session time zone when binding java.util.Date to SQL TIMESTAMP column
My table has a TIMESTAMP column. Per our convention all times in the db is supposed to be in 'UTC'.
When I insert a java.util.Date it is converted using the JVM's default TimeZone.
There seems to be ...
1
vote
1
answer
189
views
Java 11 -> 17: Groovy now uses Object getAt(String) instead of java.util.Date getAt(int)
I am upgrading a groovy app from JDK11 to JDK17. One error I had to debug was with the following code:
public static def getDayFromDate (Date date) {
return date[Calendar.DAY_OF_MONTH]
}
For those ...
0
votes
0
answers
184
views
Different Groovy behavior for java.util.Date depending on whether the app is in a jar format or not
Ran into a puzzling situation... My Groovy (4.0.18) app is working smoothly (thanks to all the help I received!) So with IntelliJ's help I packaged it up into a jar file including all dependencies and ...
-2
votes
1
answer
79
views
Enter the year and the number of weeks, return the corresponding Monday start time,
The code looks like this:
LocalDate.of(year,1,1).with(WeekFields.of(Locale.ENGLISH).weekOfWeekBasedYear(),weekNumber).with(DayOfWeek.MONDAY)
But when I count 49 weeks for this year, which is 2023, ...
2
votes
1
answer
20k
views
How do I convert a Java Date into an Instant for a given timezone? [closed]
I have an instance of the Date class and a time zone (e.g Europe/London). How do I convert this into an Instant? Is the below the correct way of doing this?
LocalDateTime localDateTime = LocalDateTime....
0
votes
1
answer
834
views
Converting LocalDate to java.util.Date [duplicate]
I'm trying to convert a java.time.LocalDate to java.util.Date, but I lose some days in the process.
Here the code that shows the issue:
public static void main(String[] args) {
var localDate = ...
0
votes
1
answer
77
views
Java compute duration of Project and Tasks doesnt work
I am trying to compute the duration Of each Project and each Task appointed to the Project, unfortunately it always returns 0.
computeDuration:
Date minDate = projectTasks[0].gettaskFromDate();...
-1
votes
1
answer
1k
views
Java Date mapping postgresql timestamp has no time, minutes and seconds
Java uses java.util.Date to save timeStamp type fields in postgresql database, and finds that there is no time, minutes and seconds, only year, month and day, which is very strange.
I have tried to ...
0
votes
0
answers
27
views
week number of anydate from datepicker [duplicate]
I want to get the week number from the date picker that user select even if the date was past date;
String dateofweek= dateselect.getText().toString();
SimpleDateFormat format = new SimpleDateFormat(&...
1
vote
1
answer
770
views
How to get correct getTimeZone by passing string value with offset in java
I have a use case where I get timeZoneId in UTC +/- format as String. Based on that I need to set correct timeZone in Java. Does anyone know the correct way of doing it?
For example:
String timeZoneId ...
-1
votes
1
answer
1k
views
How can I get the cdate field from a Date object? [closed]
Does anyone know how to grab or create the cdate value from Date? I haven't been able to figure out how to do so and I don't know how to necessarily get it. In the Date class it is there as
...
0
votes
0
answers
178
views
How to select date only from database that storing dob as datatype timestamp without timezone in java
I have a table in PostgreSQL that stores dob as datatype timestamp without timezone
example value '1997-12-03 07:00:00'.
My entity class is as follows
@Table(name = "customer")
...
0
votes
1
answer
106
views
String date convertion to Date Conversion [duplicate]
My requirement is to convert the string "2019-04-25 07:06:42.790" to Date Object with same format as "2019-04-25 07:06:42.790".
I tried to do this, but it is always giving in ...
1
vote
2
answers
3k
views
java.util.Date to kotlinx.datetime.LocalDateTime
I have a value of type java.util.Date which was obtained from a legacy third-party API. Is there a direct way of converting it to kotlinx.datetime.LocalDateTime? I know how to do it only in a ...
0
votes
3
answers
2k
views
Comparing java.utilDate with LocalDate in java
I have a method wherein have to check whether a LocalDate falls in between two java.util.Date values.
there are methods after and before in java.util.Date
and there are methods isAfter and isBefore in ...
3
votes
3
answers
3k
views
Spring jdbctemplate exception java.time.LocalDateTime cannot be cast to java.util.Date
I have a datetime type column in mysql db and file fetching column using jdbctemplate and type casting it to java.util.Date throws error.
Here is my code :
I have defined the following ...
-2
votes
2
answers
1k
views
Some Time Zones return IllegalArgumentException
This code example uses 3 time zones (EST, PST, EET).
For each Time Zone, a Date object is created and the toString() is run to print out the format being used.
Then this same String value is passed to ...
0
votes
0
answers
713
views
Elastic Search - How to return records within time intervals
I have an elastic search db deployed within an AWS VPC. It holds millions of records all with a timestamp added based on the unix datestamp (new Date().getTime()). I am trying to pull (1) record per ...
-2
votes
1
answer
157
views
How to get date from a string without formatting? [duplicate]
I have a
String s = "2020-02-22"`;
and I want to change it to Date so I can store it in my database which has has a column that does not accept anything but Date.
I tried using the ...
1
vote
0
answers
76
views
In java Trying to convert "2020-11-22T05:57:10+01:00" into Java Date object [duplicate]
try {
SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-DD'T'HH:mm:ss+hh:mm");
Date dateTime = format .parse("2020-11-22T05:57:10+01:00");
System.out.println(...
-2
votes
2
answers
2k
views
How do I create a default constructor including a Date as type Date?
In my Java College Class, I have to create the class Customer. A customer has to have a first name, the last name, a birthday and an address.
The problem I have is to fill the default constructor ...
0
votes
1
answer
162
views
How do I auto flag related records in an arraylist based on date and time?
I'm designing a simple covid 19 tracking system. The system creates Visits object that is stored in an ArrayList everytime a Customer(objects in ArrayList) visits a Shop(objects in ArrayList).
The ...
0
votes
3
answers
148
views
Calculate last third of two Dates in Java
I am searching for a method to get the last third of two dates.
first example:
Date 1 = 22:00
Date 2 = 01:00 (next day)
calculateLastThird(); (output: 00:00)
second example:
Date 1 = 22:25
Date 2 = ...
0
votes
2
answers
2k
views
Android deprecated date parsing
I use this function to parse strings into a date format
fun formatTimestampEDDMMMYYYY(date: String): String {
return E_DD_MMM_YYYY.format(Date.parse(date))
}
Whilst it works perfectly the gradle ...