on 09-05-2005 5:53 AM
Hi
I want to get the current month and year. can any one suggest how to get it?
Thanks & regards,
Anupreet
Hi Anupreet,
Try with the following code
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
String DATE_FORMAT = "MM-dd-yy";
java.text.SimpleDateFormat sdf =new java.text.SimpleDateFormat(DATE_FORMAT);
sdf.setTimeZone(TimeZone.getDefault());
java.util.Date dt1=null;
dt1=sdf.parse(sdf.format(cal.getTime()));
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupreet,
Have you tried with the code i have given?
It is short and simple. It gives you current year, month and whatever you want. Just specify in SimpleDateFormat whatever you want.
If you want Month in form of "Oct" then specify accordingly in SimpleDateFormat("<>") parameter.
Regards,
Bhavik
Message was edited by: Bhavik Devisha
try{
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
String DATE_FORMAT = "MM-dd-yy";
java.text.SimpleDateFormat sdf =new java.text.SimpleDateFormat(DATE_FORMAT);
sdf.setTimeZone(TimeZone.getDefault());
java.util.Date dt1=null;
dt1=sdf.parse(sdf.format(cal.getTime()));
}
catch(Exception e)
{
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupreet,
Use following code for getting current Year and month.
String year = (new SimpleDateFormat("yyyy").format(new Date()));
String month = (new SimpleDateFormat("MM").format(new Date()));
Regards,
Bhavik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.