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
-2
votes
1 answer

How to get date from a string without formatting?

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 LocalDate class but it's in API 26. Any help would be appreciated.
sammy
  • 3
  • 2
-2
votes
3 answers

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 it out in milliseconds using the Date class while also…
AJ Mosley
  • 11
  • 5
-2
votes
2 answers

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 since I have to assign a value to birthday. But I…
Sye
  • 1
  • 1
-2
votes
3 answers

Counting number of days of a particular month when given a duration

A duration is given. Ex: Jan 15-March 15 I want to count the number of days which belongs to each month, in that given duration. In this example, number of days of January in that duration; 15 number of days of February in that duration; 28…
direndd
  • 642
  • 2
  • 16
  • 47
-2
votes
3 answers

Why does java.sql.Timestamp extend java.util.Date

When I saw this I got baffled: public class Timestamp extends java.util.Date { //... public boolean equals(java.lang.Object ts) { if (ts instanceof Timestamp) { return this.equals((Timestamp)ts); } else { return…
estani
  • 24,254
  • 2
  • 93
  • 76
-2
votes
2 answers

“no suitable method found for between(Date, Date)" when trying to calculate difference in days between two dates

How to calculate the difference between current day and date of the object that user had previously selected from jXDatePicker swing component and that had been added as Date to that object. In my current code at the last line I'm getting this error…
mat2
  • 11
  • 4
-2
votes
1 answer

Numbers change when converting between Java.util.Date and my own date class

For a booking monitoring system I'm using a simple date class(not showing the full class): package DataBase; public class Date { private int day; private int month; private int year; public Date(int day, int month, int year) { …
BRHSM
  • 854
  • 3
  • 13
  • 48
-2
votes
1 answer

which is better for printing time in logs

I want to know whether new Date().toString or Calendar.getInstance().getTime().toString which is better since both give the same output and why choose one over the other? Scenario: I'm using them just to print time in logs so many in a Class many…
krrish0690
  • 51
  • 2
  • 11
-2
votes
1 answer

Convert java.util.Date to java.sql.Date

I am trying to get date in my database that have format like this "dd/MM/yyyy" and compare them to get latest date.. I was surprised to find that it couldn't do the conversion implicitly or explicitly - but I don't even know how I would do this, as…
-2
votes
5 answers

How to generate date with milliseconds

I tested this code: java.util.Date d=new java.util.Date(); System.out.println("date="+d); The output is: Sat May 09 02:48:42 CDT 2015 It has no milliseconds... p.s lets say if to use Date for ConcurrentLinkedHashMap (wiki link) I…
user390525
  • 263
  • 1
  • 2
  • 18
-2
votes
1 answer

Is there a way to format Date in the format explained below

I have a Date object created by new Date(); When I do String.valueOf(new Date()) I get "Mon Jan 10 11:11:11 PST 2015" Is there a way to format in the following way: Monday Jan 10, 2015 at 5:15 PM I tried DateFormat and all its examples but not…
Nick Div
  • 5,338
  • 12
  • 65
  • 127
-2
votes
3 answers

String to Date object conversion with custom format

I need to convert a date in dd/MM/yyyy format and store it to a Date object. i tried but not getting the desired result.My code : Date date=new Date(); System.out.println("Normal Date :"+date); DateFormat formatter = new…
Dev
  • 21
  • 5
-3
votes
1 answer

Java date is changing when updating date field in Oracle DB

I am parsing date field from xml and store it into oracle db for my requirement. my xml date looks like 1960-10-24T00:00:00 during unmarhsalling the xml, i am getting XMLGregorianCalendar data type for this date field.So, am…
Saravanan
  • 11,372
  • 43
  • 143
  • 213
-3
votes
1 answer

return date type with format in java

I'm trying implement get method for variable has type "Date". But when return, I want to return it with format "yyyy/MM/dd" and MUST be Date type. Example: original date: 2018/01/01T15:00.00.000+0000 I want return: 2018-01-01 and MUST be date, not…
Vũ Minh Vương
  • 163
  • 6
  • 20
-3
votes
1 answer

Convert Date to the same format as another Date

I have a requirement like, the date difference should be calculated from an input date and the current date in Talend java platform. In that case I can use TalendDate.diffDate(date1, date2) : long method, where date1 and date2 are of type…
1 2 3
21
22