I have used JCalender to get the date. It returned the date like this
Thu Mar 01 18:35:53 PST 2012
But what I need is this format.
2012 Sep 04
Here is the code I am using:
java.util.Date s = txt_dob.getDate();
I have used JCalender to get the date. It returned the date like this
Thu Mar 01 18:35:53 PST 2012
But what I need is this format.
2012 Sep 04
Here is the code I am using:
java.util.Date s = txt_dob.getDate();
Ironically, even though the snippet of code you gave us doesn't really give any indication of effort into solving the problem yourself, or tell us which JCalendar
library you're using, I think I can guess what's wrong.
You're probably just calling toString()
(possibly implicitly) on a java.util.Date
. Don't do that - it will always assume the local time zone, and a default format based on the system locale.
Instead, use SimpleDateFormat
- and remember to set the time zone appropriately, and potentially the locale. For example:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy MMM dd", Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String text = formatter.format(txt_dob.getDate());
If that doesn't work, you'll have to give us more context.
you can try out SimpleDateFormat or other Implementations of DateFormat to format your Date-Strings as needed
Found the Solution!!!!!!!!!!!! :) :)
String s = ((JTextField)txt_dob.getDateEditor().getUiComponent()).getText();