Validation of same date of birth in GWT [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How can I compare same date of births in GWT using Date?
olpPatient.getBirthday().equals(birthday);
Even if both dates are equal, that line returns false.

You can use the class com.google.gwt.user.datepicker.client.CalendarUtil. There is a method called isSameDate(Date, Date) which will just check the date, not the time of day.
From the javadoc:
Check if two dates represent the same date of the same year, even if they have different times.

It depends on how you create dates. If you get them from a DatePicker or parse a String which does not include hours and minutes, then you can use:
patient.getBirthday().getTime() == birthday.getTime();
If your dates include hours and minutes, you can do:
int day = 24 * 60 * 60 * 1000;
boolean sameDate = patient.getBirthday().getTime()/day == birthday.getTime()/day;

You are comparing Date objects by using equals() (by default, Object.equals is checking whether references to these objects are equal or not and Date.equals checking timestamps). But you need only to exract day, month, year from those objects and compare only them.

Related

Conversion of milliseconds to a specific date format [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
How can I convert the current time in milliseconds, which is a Long, to a date in specific format?
The format that I need is yyyy-MM-dd HH:mm. This should be of type Date, not String.
You are confused. The type Date is a number of milliseconds since January 1 1970 midnight UTC. It has no inherent format. There is a default system format for a Date, but you cannot alter it. You will need to format your Date as a String if you need that particular String format.

Parse String to Date in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
I have date like mm-dd-yyy in string format and I am trying to convert the same to Date object in java,
Two ways I tried in
sending the date format as "mm-dd-yyy" which is returning the wrong
date, it always returns month Jan even though the month in the
string is not "01"
sending the date format as "MM-dd-yyy" will return the correct date
as expected.
But I want to understand why the first approach returning wrong?
Can any body tell me the reason.
See the Format
M Month in year
m Minute in hour
Date and time formats are specified by pattern strings. Within the pattern strings, m is interpreted as minute in hour, and M is interpreted as Month in year.
Perhaps you should read JavaDoc API spec.
And you should check that the year of parsed date object is what you intended to. Since your string is MM-dd-yyy, "02-12-014"(which should be 2014-02-12 is actually interpreted as 0014-02-12, which can be not your intended result.

Formula of currentTimeMillis() in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
To my knowledge, System.currentTimeMillis()/1000 can show the current time in seconds since
1970-1-1 00:00:00 (YY-MM-DD HH:mm:ss)
For example
2013-10-12 21:30:00 (YY-MM-DD HH:mm:ss)
= 13815846XX (not sure whats X for)
I was wondering how to calculate it. Thanks a lot!!!!
System.currentTimeMillis() just returns the number of milliseconds since the Unix epoch (January 1st 1970, midnight UTC), as a long.
Converting that value into a string is normally the job of something like SimpleDateFormat, via Calendar and Date. Alternatively, look at Joda Time for a nicer date/time API.
If you want to start with a date and get the number of milliseconds since the Unix epoch, you'd use Calendar, set the appropriate fields and then use Calendar.getTimeInMillis(). (Or again, use Joda Time.) Be careful about time zone interactions.
You can use Epoch Converter to check your computations.
A value such as 1381584600 is most likely to be a Unix timestamp, which is the number of seconds (not milliseconds) since the Unix epoch - hence the division by 1000 that you mention.
If this doesn't tell you what you need, please ask a more precise question.

Subtract two time instances using java code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have two resultset each having only one column. The column field of both resultset contain a time entry in a format like this (2012-12-31 13:49:21.999). Now can anyone help me to find difference of time between two columns of the resultset?
e.g. if first field of column of first resultset has entry (2013-02-13 17:04:09.672) and first field of column of second resultset has entry (2012-12-31 13:49:21.999) then the program should be able to difference in the time of these two enries.
need help?
Something like:
Date date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S", Locale.ENGLISH).parse(column1);
Date date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S", Locale.ENGLISH).parse(column2);
getDateDiff(date1,date2,TimeUnit.MINUTES);
/**
* Get a diff between two dates
* #param date1 the oldest date
* #param date2 the newest date
* #param timeUnit the unit in which you want the diff
* #return the diff value, in the provided unit
*/
public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) {
long diffInMillies = date2.getTime() - date1.getTime();
return timeUnit.convert(diffInMillies,TimeUnit.MILLISECONDS);
}

Is java.sql.Date() and the mysql command sysdate [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
is the java.sql.Date() and the mysql command sysdate gives exactly the same date time?
You will run the command sysdate on the DB system . It gives you the system date of the DB server.
java.sql.Date is A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. It is different , it is a Java object which interfaces with the sql date. The JDBC driver will use the java.sql.Date object and format its data to an acceptable format while storing it in the DB and vice versa.
By itself it cannot give us a date until you feed it with some data, and it stores years, months and days while hour, minute, second and millisecond are ignored.
The SYSDATE function gives the date and time of the database server. The java.sql.Date does not give any particular date - it must be initialized to a specific date, and it only stores the date, not the time. (Internally it does store a time component as well, but it's meaningless and you're supposed to ignore it.) If you create a java.sql.Date object with
date = new java.sql.Date(System.getCurrentTimeMillis());
or something equivalent and your database is running on a different machine, you may get a different date when you call SYSDATE if the clocks on the two machines are not synchronized.
SELECT SYSDATE();
Output: 2013/07/26 04:16:55
Default Format: yyyy-MM-dd hh:mm:ss
Date a=new Date();
java.sql.Date d=new java.sql.Date(a.getTime());
System.out.println(d);
Output: 2013/07/26
Default Format: yyyy-MM-dd

Categories

Resources