Questions tagged [java.util.date]

Through Java 7, the official class for representing a moment in time, using a thin wrapper around the number of milliseconds from epoch (1970-01-01). In Java 8, java.time.Instant and related classes were introduced as a replacement.

In the JDK through Java 7, the java.util.Date class is very widely used and contrary to what its name suggests, represents an instant rather than a "date" (i.e. a particular day). Date objects are mutable.

In Java 8, a new package java.time was introduced, which contains java.time.Instant to be used to represent an instant. This package should be preferred over using the old java.util.Date classes when writing new code.

323 questions
-1
votes
1 answer

How do I convert a Java Date into an Instant for a given timezone?

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.ofInstant(date.toInstant(),…
-1
votes
1 answer

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.ofInstant(date.toInstant(), zoneId); // instant of…
-1
votes
4 answers

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 days from current time. I am using a tool that…
user3384231
  • 3,641
  • 2
  • 18
  • 27
-1
votes
4 answers

get Date without time in java

I want to get a Date without time, but always failed. below is my codes: long curLong = System.currentTimeMillis(); curLong = curLong - curLong % TimeUnit.DAYS.toMillis(1); Date date = new Date(curLong); System.out.println("date = "…
Alan
  • 143
  • 1
  • 6
-1
votes
2 answers

Gregorian Date to Date

This should be quite simple customerSearch.get("DateOfBirth") where customerSearch is a HashMap and it's a Gregorian Date. But I need a normal Date object. I tried Date dateOfBirth = new Date( ((GregorianCalendar)…
-1
votes
3 answers

Compare calendar time by minutes

I'd like to calculate the difference between "MON 17:00" and "Tue 5:00" in "minutes" How can I achieve this using Java. I don't quite understand how to use calendar and simpleDateFormat doesn't support the Mon,Tue,Wed,e.t.c feature. Any help? The…
Karl Garcia
  • 45
  • 11
-1
votes
4 answers

util.sql dates in json response

I'm trying to pass a java util date to my json response without succes. If i System.out.println the dates i get "1970-01-01 01:00:00.263" correct format. System.out.println("from date: " + fromDate); System.out.println("to date: " +…
Anders Pedersen
  • 2,255
  • 4
  • 25
  • 49
-1
votes
3 answers

Date Conflicts(java.util.Date)

In our project I have faced a problem that is Date date = new Date(); is converted to string String dateToString = date.toString(); Again I want to convert same string (dateToString) as util date. Any Solution? Some Code Snippet: Date…
maheshd
  • 13
  • 6
-1
votes
2 answers

Using dropdown for DOB in servlet giving wrong output

I am trying to write a code in Servlet for DOB and DOJ using Netbeans, MySQL and Tomcat. Issue is when I am saving the date it goes into MySQL table but date automatically changes. I am using 3 drop down box for - dd mm yyyy and suppose I select 24…
Amit Roy
  • 33
  • 5
-1
votes
1 answer

Java validate date in yyyyMMddHHmmss

i want to validate the given date format as yyyyMMddHHmmss in java. Conditions: It should meet the format yyyyMMddHHmmss. It should validate the current date. It should validate hours which can be +3 hours or -3 hours variance with the current…
haja
  • 135
  • 1
  • 4
  • 12
-1
votes
2 answers

Convert java.util.date format into another different java.util.date format

How Can I convert this java.util.Date format: 2015-01-16 00:00:00.0 to this java.util.Date format: 2015-01-16 00:00:00 GMT+00:00
Shiroga
  • 145
  • 2
  • 8
  • 20
-1
votes
3 answers

grails sort by date not working

I have domain object named Roll and on the list page i want to show the user all the Roll objects iterating through a list, sorted by entry date. Here is the code i am using [rollList: Roll.findAll(sort:"rollDate"){userid==uid}] rollDate is a field…
Arpan Solanki
  • 817
  • 1
  • 17
  • 28
-2
votes
1 answer

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 convert it to java.sql.Timestamp at the Java level,…
-2
votes
1 answer

How can I get the cdate field from a Date object?

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 private transient BaseCalendar.Date cdate; I don't see…
-2
votes
2 answers

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 a Constructor and used to create a new Date…
Unhandled Exception
  • 1,427
  • 14
  • 30