Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: date problem

  1. #1
    Member
    Join Date
    Sep 2018
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default date problem

    Hello,
    For my Java class I have to output the date in multiple formats. So I was going to start very simple and came up with the following code
    [code]
    import java.util.Date;
    import java.text.*;

    public class TestDate {

    public static void main(String[] args) {

    Date date1 = new Date();

    SimpleDateFormat for1 = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat for2 = new SimpleDateFormat("MM/dd/yy");

    System.out.println("yyyy/MM/dd");
    System.out.println(for1.format(date1));
    System.out.println("MM/dd/yy");
    System.out.println(for2.format(date1));

    }

    }
    [\code]

    I am using Eclipse and the output is

    MM/dd/yy
    10/15/18

    I was expecting

    yyyy/MM/dd
    2018/10/15
    MM/dd/yy
    10/15/18

    I don't have any errors and I notice that when I click the run button, the output console flashes. It's very fast, but it looks like it initially flashes my intended output.
    Any ideas as to what is happening?

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: date problem

    It ran just fine for me and printed what you expected. How many times did you try and run it?

    Regards,
    Jim

  3. #3
    Member
    Join Date
    Sep 2018
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: date problem

    A few times. With different variations of commenting out the System.out.println statements. For example

    System.out.println("yyyy/MM/dd");
    System.out.println(for1.format(date1));
    System.out.println("MM/dd/yy");
    // System.out.println(for2.format(date1));

    So maybe somethings wrong with my install of Eclipse?

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: date problem

    Are you certain you are running the exact code that you posted? I run that code and I get this each time. I'm also running Java 10 but that shouldn't make any difference.

    yyyy/MM/dd
    2018/10/15
    MM/dd/yy
    10/15/18

    Regards,
    Jim

  5. #5
    Member
    Join Date
    Sep 2018
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: date problem

    I feel pretty confident that it's the exact code. I selected all, and copied it to this forum.
    I have another computer. I'll try installing Eclipse on it, and copy and paste to it, to see if it works.

  6. #6
    Member
    Join Date
    Sep 2018
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: date problem

    So, reinstalling did the trick. I don't see where I do this, but how do I mark this as solved?

  7. #7
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: date problem

    As far as I know you can't. I am in a different Java forum that also uses VBulletin and you can't do it there either. Some folks mark it in the subject but I just leave it alone. Usually, folks will figure it out when they read the thread.

    Regards,
    Jim

Similar Threads

  1. Regarding reading of DATE FORMAT ISSUE and its VALIDATION PROBLEM
    By Naresh0523 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 6th, 2017, 01:44 AM
  2. problem Comparing date and month from dates
    By desire7696 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2012, 10:08 AM
  3. Date problem
    By java_wannabe in forum Java Theory & Questions
    Replies: 7
    Last Post: April 22nd, 2011, 09:25 AM
  4. JAVASCRIPT DATE DIFFERENCE PROBLEM
    By jai in forum Other Programming Languages
    Replies: 3
    Last Post: April 5th, 2011, 09:11 AM
  5. sql date problem
    By realosso in forum JDBC & Databases
    Replies: 2
    Last Post: June 3rd, 2010, 08:32 AM