336 questions
-2
votes
2
answers
266
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 ...
-3
votes
1
answer
107
views
java.util.Date format mismatch while setting value in spring application [closed]
I have a date "08-10-2020". I want to set that string into a java.util.Date property in the same format. But even after using SimpleDateFormat to format the date, it is still setting in &...
0
votes
0
answers
73
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 ...
0
votes
2
answers
464
views
Year, month, day, hours, minutes to Date without "magic"
Let's get this over with.
How do you convert a LocalDateTime to a java.util.Date without any "magic tricks" pulled by Java (which are becoming less and less amusing to me)?
The year, month, ...
1
vote
1
answer
194
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
1
answer
406
views
How to get Date in format MMM d, YYYY in java [duplicate]
I have a model class with 'Date' type field.
//Model.java
private Date createDate;
I am trying to convert the database value of this createDate (which is YYYY-MM-DD format) to MMM d, YYYY, i.e., I ...
0
votes
0
answers
188
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 ...
4
votes
2
answers
2k
views
After migrating to Java 17, the date is displayed inaccurately
We've recently transitioned our application from Java 11 to Java 17. Subsequent to the deployment, we've noticed that certain records exhibit a discrepancy where dates are displaying with a one-day ...
-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, ...
-4
votes
1
answer
123
views
not able to convert \ format java.util.Date to yyyy-mm-dd [duplicate]
I am trying to convert java.util.Date to java.util.Date but in different format
Wed Oct 11 10:00:00 CDT 2023 -->
2023-10-11T10:00:00.000Z
I show lot of post and also tried different solutions ...
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....
2
votes
2
answers
180
views
Why Date class does not support Internationalization?
I was going through the different ways that we can get Date and Time in java, while reading the documentation could not understand what the below quote mean.
Unfortunately, the API for these ...
0
votes
1
answer
845
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 = ...
-1
votes
1
answer
202
views
TimeZone Date Conversion [Convert a Date object to a specified timeZone Date Object]
My approach :
// initailize date object
Date date = new Date();
// get time zone
ZoneId zoneId = ZoneId.of("Asia/Dubai");
// create zonedDateTime object
ZonedDateTime zdt = ZonedDateTime....
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
vote
0
answers
85
views
Converting UTC time to Date object [duplicate]
I am trying to get the current UTC time and convert it into a Date object:
OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
Date date = Date.from(now.toInstant());
The problem I ...
-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 ...
5
votes
1
answer
1k
views
Why does the LocalDateTime conversion to java.util.Date is shifting for very old date?
I am having trouble with converting old dates from java.time.LocalDateTime to java.util.Date
I tried a lot of variation and it still has the same shifted dates. I would assume that it is some weird ...
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(&...
0
votes
2
answers
352
views
How to get Date in java.util.Date instead of Unix Timestamp in bash script?
I have an .sh script on my Linux server.
I need the date in milliseconds in Java, but everything I find on the net is giving me Unix Timestamp.
Like this: date=$(date -d 'today 00:00:00' "+%s&...
1
vote
1
answer
775
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 ...
3
votes
3
answers
607
views
java.util.Date special date 1980-04-06: wrong hour
We faced following problem:
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", java.util.Locale.GERMAN);
String dateInString = "06-04-1980";
Date date = ...
-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
2
answers
91
views
Problem in Grails application started suddenly
I have a Grails 4.0.3 rest api in production running since last year without major problems.
Unfortunately since last week It is in trouble because of some RabbitMQ request in the queue. My applicaion ...
0
votes
0
answers
183
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")
...
1
vote
1
answer
456
views
Is value returned by java.util.Date.getTime() same as java.time.ZonedDateTime.getEpochSeconds()?
I have a legacy application that is passing Date using
java.util.Date
and a new service that is providing date using
java.time.ZonedDateTime
.
My use case is to compare both the dates and ...
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
1
answer
858
views
Is there a way to represent BC dates with java.util.date?
Yes, I understand that java.util.Date is extremely outdated. That being said, is there a way to represent dates before 1 CE using this class, or must I migrate to a different class?
1
vote
2
answers
4k
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 ...
1
vote
0
answers
103
views
How to solve PWC6338: Cannot convert "2022-02-01" for the attribute birthDate of the bean java.util.Date?
So below is the code I made to create a register form for user to register for new account.
signUp.html
<form class="user" method="post" action="signUp.jsp">
&...
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 ...
0
votes
4
answers
5k
views
How to format Date object to match @JsonFormat?
I have a json formatted response Date to the controller that is like this:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "America/Chicago")
private Date date;
So when I ...
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 ...
0
votes
1
answer
163
views
Android Date.from() taking device timezone into account?
Using the following code in Java8 -
newTable.LogDate = Date.from(ZonedDateTime.of(year, month, day, 0, 0, 0, 0, ZoneId.of("GMT")).toInstant());
The LogDate is ending up adjusted for my (and ...
-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 ...
2
votes
4
answers
11k
views
How to convert java.util.Date to java.time.LocalDate and preserve date/time
I'm trying to convert a java.util.Date to java.time.LocalDate:
[java.util.Date instance].toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
However, there is a case when [java.util.Date ...
0
votes
0
answers
720
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 ...
0
votes
2
answers
2k
views
cannot find symbol - symbol class date - Location package java.util
I can not find my error. The program says that can not fin class Date. Please help me to find the error.
It is a inheritance and Polymorphism class.
I have classes: GeometricObject, Circle, and ...
-2
votes
1
answer
158
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 ...
0
votes
1
answer
656
views
java parse date GRAVE null
In this code,
String str="Sun Feb 07 00:27:16 CET 2021";
SimpleDateFormat sdf=new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");
try {
java.util.Date date=...
1
vote
0
answers
77
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
3
answers
291
views
How to get the time that it took to type a sentence in Java
I have a kind of complex problem that I hope I can get some help on.
My teacher has asked for a homework question that we find how long it took us to type a sentence "Hello World!" and print ...
-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 ...
1
vote
2
answers
865
views
Good way for Java Date comparison without time
There is requirement to see if some date (ex: expiry date) is greater than or equal to today. Presently JODA time library has been used to achieve this simple comparison. Even some post are ...
0
votes
1
answer
167
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 ...
1
vote
1
answer
2k
views
Parsing HTML date input into Timestamp in Java Servlet
Recently I'm having a problem with Timestamp and HTML input type Date:
This is my HTML/JSP:
<div class="form-group">
<label>Your day of birth</label>
<input class=&...
0
votes
3
answers
149
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 = ...
10
votes
2
answers
14k
views
How to convert java.time.format.TemoralAccessor to java.util.Date
How can I convert TemporalAccessor to java.util.Date?
TemporalAccessor accessor = functionReturnsTemporalAccessor()
Date date = Date.from(accessor)
Date.from() does not accept TemporalAccessor, is ...
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 ...
-1
votes
4
answers
6k
views
Add 30 days in future from current epoch time Java
I am getting the current time in epoch. How can I add 1 month in future?
Date date = new Date();
int epoch = date.getTime();
Datatype for epoch - integer($int64)
To be precise: I want to add 30 ...