It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I created a datepicker and a time picker that apply the date and time in EditText field.
Now I need to do a check, that the date and time inserted are forward in time than the current date. need accept only the date and time that go into the future...
how do?
You need to use a Calendar object to get the current date...
Calendar currentDate = Calendar.getInstance();
Then make a Calendar for the date entered by the user, probably using something like this...
Calendar enteredDate = Calendar.getInstance();
enteredDate.set(Calendar.DATE, dateValue);
enteredDate.set(Calendar.MONTH, monthValue);
enteredDate.set(Calendar.YEAR, yearValue);
Then compare the 2...
boolean isAfterToday = enteredDate.after(currentDate);
If it is true, the entered date is after today's date.
If you need to use time values, specify them in the enteredDate.set() methods - refer to the Java documentation at http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to compare current date with date which is entered by the user.
In my form I have fields as
Name:
TicketNO:
ContactNo:
Issue Date: 13/4/2013
Return Date: 17/4/2013
The above data is collected from user and entered into database and I want to compare issue date with the system date and on return date i want to send mail to user that your Return date is today.
The database is Oracle 11g.
You need the basic date comparion between current date and input date given by the user right?
Do it like this:
Calendar userDate = Calendar.getInstance();
Calendar currentDate = Calendar.getInstance();
userDate.setTime(inputDate);//here inputDate is date given by the user.
if(!userDate.before(currentDate)) {
// user date is after current date(today).
} else {
// user date is before current date(today).
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
For example:
I was able to get the timestamp
String date="123456765343";
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(Long.parseLong(date)*1000);
Date d = cal.getTime(); // now this reprents the unix timestamp
I would like to have the date looking like this :
14/Mar/2013 6:31:34 PM
You would have to use SimpleDateFormat (and you don't need the Calendar):
Date d = new Date(Long.parseLong(date) * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss a");
System.out.println(sdf.format(d));
You can use SimpleDateFormat to format your date.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I will get the date from mySQL in the format of YEAR-MONTH-DAY ex(2013-02-01).
How would i be able to retrieve the Date using ResultSet
and then compare it with todays date to see if its a year old.
ResultSet has getDate() methods that will return a Date object. After that, here's a short way to compare them, if you don't care too much about precision or leap years or such:
Date fromDatabase = ...;
Date now = new Date();
long daysBetween = TimeUnit.DAYS.convert(now.getTime() - fromDatabase.getTime(), TimeUnit.MILLISECONDS);
if (daysBetween > 365) { ... }
If you mean that the date is stored as a string value instead of as a date in the database, you can parse it like new SimpleDateFormat("yyyy-MM-dd").parse("2013-02-01").
When dealing with dates in databases, keep time zones in mind. It can get tricky keeping things straight.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm confused how to create based on the date the transaction code in java and mysql, help me.
You just need to get the Date value from System.
There is some way to get it :
Get Date in Java
Filed under: Java, Programming — Leave a comment
30 November 2011
I’ll give you 2 example.
Example 1:
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(df.format(cal.getTime()));
Or youcan use Date instead of Calendar, like this:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dt = new Date();
System.out.println(sdf.format(dt));
You can manipulate the Date Format.
And after that you can manipulate that value to somehing like your transcation code you want.
Like
Int index = 0
String transcode;
transcode = sdf &index
index +=1
just be more creative.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to save any date type format as user wishes: The date should be saved to the datebase in the format the user has entered (for example mm/dd/yy, dd/mm/yy or yy/dd/mm).
How can I achieve this?
Maybe try it this way.
Store user preferred date format in his profile and all dates in some default format. When you want to show date to user format it according to his preferences like
String userFormat="yy/MM/dd";
SimpleDateFormat sdf = new SimpleDateFormat(userFormat);
Date someDate = new Date();
String formatedDate = sdf.format(someDate);
System.out.println(formatedDate);
But thats just one of options.