How do I format JDateChooser into dd-mm-yyyy?
up vote
2
down vote
favorite
I am trying to output the current date format into:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");, but it is outputting like this:
Fri Dec 02 14:03:59 AEST 2016
Here is my code:
JDateChooser datePurchased = new JDateChooser();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date newDate = new Date();
datePurchased.setDate(newDate);
I am now printing the result like this:
System.out.println(newDate.toString());
But this does not print out what I want, as per above.
My goal output is: 02/12/2016, how do I go about doing this, I've tried looking around but I cannot find the likes to solve my problem.
Thank you in advance.
java string date simpledateformat jdatechooser
add a comment |
up vote
2
down vote
favorite
I am trying to output the current date format into:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");, but it is outputting like this:
Fri Dec 02 14:03:59 AEST 2016
Here is my code:
JDateChooser datePurchased = new JDateChooser();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date newDate = new Date();
datePurchased.setDate(newDate);
I am now printing the result like this:
System.out.println(newDate.toString());
But this does not print out what I want, as per above.
My goal output is: 02/12/2016, how do I go about doing this, I've tried looking around but I cannot find the likes to solve my problem.
Thank you in advance.
java string date simpledateformat jdatechooser
where are you using thedateFormatobject?
– Gurwinder Singh
Dec 2 '16 at 4:11
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to output the current date format into:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");, but it is outputting like this:
Fri Dec 02 14:03:59 AEST 2016
Here is my code:
JDateChooser datePurchased = new JDateChooser();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date newDate = new Date();
datePurchased.setDate(newDate);
I am now printing the result like this:
System.out.println(newDate.toString());
But this does not print out what I want, as per above.
My goal output is: 02/12/2016, how do I go about doing this, I've tried looking around but I cannot find the likes to solve my problem.
Thank you in advance.
java string date simpledateformat jdatechooser
I am trying to output the current date format into:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");, but it is outputting like this:
Fri Dec 02 14:03:59 AEST 2016
Here is my code:
JDateChooser datePurchased = new JDateChooser();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date newDate = new Date();
datePurchased.setDate(newDate);
I am now printing the result like this:
System.out.println(newDate.toString());
But this does not print out what I want, as per above.
My goal output is: 02/12/2016, how do I go about doing this, I've tried looking around but I cannot find the likes to solve my problem.
Thank you in advance.
java string date simpledateformat jdatechooser
java string date simpledateformat jdatechooser
edited Dec 2 '16 at 4:17
ΦXocę 웃 Пepeúpa ツ
32.6k113760
32.6k113760
asked Dec 2 '16 at 4:09
juiceb0xk
270420
270420
where are you using thedateFormatobject?
– Gurwinder Singh
Dec 2 '16 at 4:11
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12
add a comment |
where are you using thedateFormatobject?
– Gurwinder Singh
Dec 2 '16 at 4:11
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12
where are you using the
dateFormat object?– Gurwinder Singh
Dec 2 '16 at 4:11
where are you using the
dateFormat object?– Gurwinder Singh
Dec 2 '16 at 4:11
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
The first part is simple enough, a Date is a representation in epoch time and doesn't have a modifiable format. Instead, you format it when you want to display it (or otherwise obtain a String representation). Additionally, you need M for months (m is minutes) and if you want / use that instead of -. For example,
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = new Date();
System.out.println(dateFormat.format(newDate));
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
edit:
if your goal output is: 02/12/2016
then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
add a comment |
up vote
0
down vote
Use this simple code:
bill_date.setDateFormatString("yyyy-MM-dd");
In here bill_date is instance of the JDateChooser.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The first part is simple enough, a Date is a representation in epoch time and doesn't have a modifiable format. Instead, you format it when you want to display it (or otherwise obtain a String representation). Additionally, you need M for months (m is minutes) and if you want / use that instead of -. For example,
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = new Date();
System.out.println(dateFormat.format(newDate));
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
accepted
The first part is simple enough, a Date is a representation in epoch time and doesn't have a modifiable format. Instead, you format it when you want to display it (or otherwise obtain a String representation). Additionally, you need M for months (m is minutes) and if you want / use that instead of -. For example,
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = new Date();
System.out.println(dateFormat.format(newDate));
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The first part is simple enough, a Date is a representation in epoch time and doesn't have a modifiable format. Instead, you format it when you want to display it (or otherwise obtain a String representation). Additionally, you need M for months (m is minutes) and if you want / use that instead of -. For example,
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = new Date();
System.out.println(dateFormat.format(newDate));
The first part is simple enough, a Date is a representation in epoch time and doesn't have a modifiable format. Instead, you format it when you want to display it (or otherwise obtain a String representation). Additionally, you need M for months (m is minutes) and if you want / use that instead of -. For example,
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = new Date();
System.out.println(dateFormat.format(newDate));
answered Dec 2 '16 at 4:13
Elliott Frisch
150k1388173
150k1388173
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
add a comment |
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
edit:
if your goal output is: 02/12/2016
then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
edit:
if your goal output is: 02/12/2016
then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
add a comment |
up vote
1
down vote
up vote
1
down vote
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
edit:
if your goal output is: 02/12/2016
then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
edit:
if your goal output is: 02/12/2016
then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy
edited Dec 2 '16 at 4:46
Jobin Joseph
2,93631935
2,93631935
answered Dec 2 '16 at 4:13
ΦXocę 웃 Пepeúpa ツ
32.6k113760
32.6k113760
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
add a comment |
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
Thank you very much for your help.
– juiceb0xk
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
@juiceb0xk you are welcome
– ΦXocę 웃 Пepeúpa ツ
Dec 2 '16 at 4:15
add a comment |
up vote
0
down vote
Use this simple code:
bill_date.setDateFormatString("yyyy-MM-dd");
In here bill_date is instance of the JDateChooser.
add a comment |
up vote
0
down vote
Use this simple code:
bill_date.setDateFormatString("yyyy-MM-dd");
In here bill_date is instance of the JDateChooser.
add a comment |
up vote
0
down vote
up vote
0
down vote
Use this simple code:
bill_date.setDateFormatString("yyyy-MM-dd");
In here bill_date is instance of the JDateChooser.
Use this simple code:
bill_date.setDateFormatString("yyyy-MM-dd");
In here bill_date is instance of the JDateChooser.
edited Nov 9 at 8:20
Unheilig
11.9k165283
11.9k165283
answered Nov 9 at 7:56
Janindu Praneeth Weerawarnakul
3810
3810
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40924635%2fhow-do-i-format-jdatechooser-into-dd-mm-yyyy%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
where are you using the
dateFormatobject?– Gurwinder Singh
Dec 2 '16 at 4:11
SimpleDateFormat
– rafid059
Dec 2 '16 at 4:12