i have a Jspinner which shows current date("yyyy//mm//dd" in this format) and i want to get only current date not time,when i use System.out.println(Spinner.getvalue()).It also shows time like this(Mon Sep 09 02:47:53 IST 2013).i just want current date 2013/09/08
how to get date value from Jspinner excluding time
9.3k views Asked by sam At
2
There are 2 answers
0
On
It's seems that you need to use some date converting tool like SimpleDateFormat.
SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
String spinnerValue = formater.format(Spinner.getvalue());
System.out.println(spinnerValue);
All SimpleDateFormat info and date patterns can be found here: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
From JSpinner javadoc:
This means when you call
getValue()
method you'll get ajava.util.Date
object (since you're usingSpinnerDateModel
I guess). When you useSystem.out.println(Spinner.getvalue())
the output shows the defaulttoString()
implementation fromjava.util.Date
class which is long and includes the time.If you want to show the date in this format
yyyy/mm/dd
try this:Note: don't get confused about
java.util.Date
object and itsString
representation.