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.










share|improve this question
























  • where are you using the dateFormat object?
    – Gurwinder Singh
    Dec 2 '16 at 4:11










  • SimpleDateFormat
    – rafid059
    Dec 2 '16 at 4:12















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.










share|improve this question
























  • where are you using the dateFormat object?
    – Gurwinder Singh
    Dec 2 '16 at 4:11










  • SimpleDateFormat
    – rafid059
    Dec 2 '16 at 4:12













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 the dateFormat object?
    – 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










  • 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












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));





share|improve this answer





















  • Thank you very much for your help.
    – juiceb0xk
    Dec 2 '16 at 4:15


















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






share|improve this answer























  • 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


















up vote
0
down vote













Use this simple code:



  bill_date.setDateFormatString("yyyy-MM-dd");


In here bill_date is instance of the JDateChooser.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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));





    share|improve this answer





















    • Thank you very much for your help.
      – juiceb0xk
      Dec 2 '16 at 4:15















    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));





    share|improve this answer





















    • Thank you very much for your help.
      – juiceb0xk
      Dec 2 '16 at 4:15













    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));





    share|improve this answer












    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));






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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


















    • 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












    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






    share|improve this answer























    • 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















    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






    share|improve this answer























    • 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













    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






    share|improve this answer














    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







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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


















    • 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










    up vote
    0
    down vote













    Use this simple code:



      bill_date.setDateFormatString("yyyy-MM-dd");


    In here bill_date is instance of the JDateChooser.






    share|improve this answer



























      up vote
      0
      down vote













      Use this simple code:



        bill_date.setDateFormatString("yyyy-MM-dd");


      In here bill_date is instance of the JDateChooser.






      share|improve this answer

























        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.






        share|improve this answer














        Use this simple code:



          bill_date.setDateFormatString("yyyy-MM-dd");


        In here bill_date is instance of the JDateChooser.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 8:20









        Unheilig

        11.9k165283




        11.9k165283










        answered Nov 9 at 7:56









        Janindu Praneeth Weerawarnakul

        3810




        3810






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Landwehr

            Reims

            Schenkenzell