Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:26:02+00:00 2026-05-27T10:26:02+00:00

I have a class with the constructor: … Date d1; Date d2; public DateClass(Date

  • 0

I have a class with the constructor:

...
Date d1;
Date d2;
public DateClass(Date d1, Date d2) {
   this.d1 = d1;
   this.d2 = d2;
}
...

Then in another class I want to use this constructor:

...
DateClass d = new DateClass(what I should I write here to create Date in format mm-dd-yyyy);
System.out.println(d);
...

Thank you!
P.S This in not a part of a homework. I really do not know how to do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:26:03+00:00Added an answer on May 27, 2026 at 10:26 am

    You can make a new Date by calling the constructor.

    // you specify year1, month1, day1
    DateClass d = new DateClass(new Date(year1-1900, month1-1, day1),
        new Date (year2-1900, month2-1, day2);
    

    This is the simplest way, and will certainly work; however, as Carlos Heuberger correctly notes, this is deprecated, meaning that other ways are preferred. You can also make a new Date through DateFormat:

    DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
    Date d1 = df.parse("12-10-2011"); // for example, today's date
    Date d2 = df.parse("01-01-1900"); // use your own dates, of course
    

    To be able to print in mm-dd-yyyy format, implement toString:

    public String toString(){
        DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
        return "Date 1: " + df.format(d1) + " Date 2: " + df.format(d2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a constructor question for C#. I have this class: public partial class
I have this class constructor AppData(Map params, Operations operation) where Operations is public enum
I have a class whose constructor takes a const reference to a string. This
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a class ReportingComponent<T> , which has the constructor: public ReportingComponent(IQueryable<T> query) {}
I have this class constructor: Pairs (int Pos, char *Pre, char *Post, bool Attach
I have a class which I use to plot things then save them to
I have a class where I use this to initialize a void* pointer. But
I have a class whose new method has been made private because I want
Is there a way to have a partial class' constructor call another method that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.