0

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();
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

3 Answers3

0

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

you can try out SimpleDateFormat or other Implementations of DateFormat to format your Date-Strings as needed

jethroo
  • 2,086
  • 2
  • 18
  • 30
0

Found the Solution!!!!!!!!!!!! :) :)

String s = ((JTextField)txt_dob.getDateEditor().getUiComponent()).getText();
  • 3
    You never even asked a proper question, which makes it pretty hard to understand what the "solution" is really about. Please read http://tinyurl.com/so-hints before you ask your next question. – Jon Skeet Sep 21 '12 at 22:24