how do i get todays dat without the time
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
it doesnt matter if its in a jsp page or a servlet. its all the same.
heres two ways that i know of getting the date but the time and timezone comes with it.
Date date = new Date();
java.util.Date today = new java.util.Date();
it outputs the date like this...
Fri Feb 11 11:58:17 GMT 2005
i want the date in the format of 11-Feb-2005 because i need to use them with an oracle database.
is there any way i can get it like that?
i might be able to strip out just the fields i want in the above format and then use some sort of toString() method to format them the way i need. but i dont know how to do that.
any ideas?
heres two ways that i know of getting the date but the time and timezone comes with it.
Date date = new Date();
java.util.Date today = new java.util.Date();
it outputs the date like this...
Fri Feb 11 11:58:17 GMT 2005
i want the date in the format of 11-Feb-2005 because i need to use them with an oracle database.
is there any way i can get it like that?
i might be able to strip out just the fields i want in the above format and then use some sort of toString() method to format them the way i need. but i dont know how to do that.
any ideas?
Whats in a name?
posted 20 years ago
http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html
And there's also:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Date.html
[ February 11, 2005: Message edited by: Ben Souther ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html
And there's also:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Date.html
[ February 11, 2005: Message edited by: Ben Souther ]
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Graham
Another alternative is to use the SimpleDateFormat class.
SimpleDateFormat Javadoc
In your case, it would look like:
Hope it helps
CT
Another alternative is to use the SimpleDateFormat class.
SimpleDateFormat Javadoc
In your case, it would look like:
Hope it helps
CT
posted 20 years ago
The format your date is displayed in does not matter if you use a PreparedStatement and bind your query parameters accordingly.
[ February 11, 2005: Message edited by: Paul Sturrock ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
i want the date in the format of 11-Feb-2005 because i need to use them with an oracle database.
The format your date is displayed in does not matter if you use a PreparedStatement and bind your query parameters accordingly.
[ February 11, 2005: Message edited by: Paul Sturrock ]
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi Paul
this is way I used to compare with oracle
it'll work
..........
..........
// SET THE FORMAT
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
// MAKE A STRING
String strDt=request.getParameter("DD")+"/"+request.getParameter("MM")+"/"+request.getParameter("YY");
// MAKE UTIL DATE
java.util.Date utilDate = formatter.parse(strDt);
try{utilDate = formatter.parse(utilDate);}catch(ParseException p){}
// CONVERT UTIL DATE TO SQL DATE
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
String qry="SELECT NAME FROM FRIEND LIST WHERE DOB=?";
pstmt=conn.prepareStatement(qry);
pstmt.setDate(1,sqlDate);
ResultSet rs=pstmt.executeQuery();
..........
..........
Vijay
this is way I used to compare with oracle
it'll work
..........
..........
// SET THE FORMAT
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
// MAKE A STRING
String strDt=request.getParameter("DD")+"/"+request.getParameter("MM")+"/"+request.getParameter("YY");
// MAKE UTIL DATE
java.util.Date utilDate = formatter.parse(strDt);
try{utilDate = formatter.parse(utilDate);}catch(ParseException p){}
// CONVERT UTIL DATE TO SQL DATE
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
String qry="SELECT NAME FROM FRIEND LIST WHERE DOB=?";
pstmt=conn.prepareStatement(qry);
pstmt.setDate(1,sqlDate);
ResultSet rs=pstmt.executeQuery();
..........
..........
Vijay
Robert Johnson
Ranch Hand
Posts: 32
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
i got it working, this is the way i did it...
<%!
public String getToDaysDate(String s)
{
String months[]={"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"
};
Calendar cal=Calendar.getInstance();
if (s=="/")
return cal.get(Calendar.DATE)+"-"+months[cal.get(Calendar.MONTH)]+"-"+cal.get(cal.YEAR);
else
return (cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DATE)+"/"+cal.get(cal.YEAR);
}
String today1=getToDaysDate("/");
out.println("<br>date is "+today1);
%>
but how do you check to see if one date is either in the future or the past.
for example an application form will have two dates (stored in the database). a start date which tells the jsp page to display the application form and an end date which tells the jsp page not to display it anymore.
so if i have todays date 11-Feb-2005 and the end date (for example 12-Feb-2005), how can i check to see if the date is in the past or future.
the play date and end date will not be the same date so i cant just compare the values. the dates are stored in Strings so maybe i will have to convert them to some other date format?
any ideas?
<%!
public String getToDaysDate(String s)
{
String months[]={"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"
};
Calendar cal=Calendar.getInstance();
if (s=="/")
return cal.get(Calendar.DATE)+"-"+months[cal.get(Calendar.MONTH)]+"-"+cal.get(cal.YEAR);
else
return (cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DATE)+"/"+cal.get(cal.YEAR);
}
String today1=getToDaysDate("/");
out.println("<br>date is "+today1);
%>
but how do you check to see if one date is either in the future or the past.
for example an application form will have two dates (stored in the database). a start date which tells the jsp page to display the application form and an end date which tells the jsp page not to display it anymore.
so if i have todays date 11-Feb-2005 and the end date (for example 12-Feb-2005), how can i check to see if the date is in the past or future.
the play date and end date will not be the same date so i cant just compare the values. the dates are stored in Strings so maybe i will have to convert them to some other date format?
any ideas?
Whats in a name?
Robert Johnson
Ranch Hand
Posts: 32
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
here is a way of doing it but i have to convert my String to the GregorianCalendar format( eg, from '11-Feb-2005' to
'2005, Calender.FEBRUARY, 11'
Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);
// Determine which is earlier
boolean b = xmas.after(newyears); // false
b = xmas.before(newyears); // true
// Get difference in milliseconds
long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();
// Get difference in seconds
long diffSecs = diffMillis/(1000); // 604800
// Get difference in minutes
long diffMins = diffMillis/(60*1000); // 10080
// Get difference in hours
long diffHours = diffMillis/(60*60*1000); // 168
// Get difference in days
long diffDays = diffMillis/(24*60*60*1000); // 7
'2005, Calender.FEBRUARY, 11'
Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);
// Determine which is earlier
boolean b = xmas.after(newyears); // false
b = xmas.before(newyears); // true
// Get difference in milliseconds
long diffMillis = newyears.getTimeInMillis()-xmas.getTimeInMillis();
// Get difference in seconds
long diffSecs = diffMillis/(1000); // 604800
// Get difference in minutes
long diffMins = diffMillis/(60*1000); // 10080
// Get difference in hours
long diffHours = diffMillis/(60*60*1000); // 168
// Get difference in days
long diffDays = diffMillis/(24*60*60*1000); // 7
Whats in a name?
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Not much to do with JSP, so off to the Java in General(intermediate) forum...
| It would give a normal human mental abilities to rival mine. To think it is just a tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |










