Shawn
Shawn

Reputation: 307

Changing the Date format from one class to another

I am using this class right now.

http://www.cse.yorku.ca/common/type/api/type/lib/CreditCard.html

I have a credit card, I used the method of getExpiryDate() for my credit card. And it gives me the date in a form of: Mon April 06 09:23:10 EDT I'm looking to have the date in this form:

06/04/2015 and the time is not needed.

    PrintStream out = System.out;
    Scanner in = new Scanner(System.in);

    GlobalCredit credit1 = new GlobalCredit().getRandom();

    out.print("Enter report range in years ... ");
    int range = in.nextInt();
    out.println("Cards expiring before " + range + " year(s) from now: ");



    for (CreditCard cc : credit1)
    {

        out.println(cc.getNumber() + "\t");
        out.print(cc.getExpiryDate());

    }

thats part of my code, (didnt copy beginning). I got to do something in the for statement. I got to relate cc.getExpiryDate() to Date Class somehow

Upvotes: 0

Views: 78

Answers (3)

M Abbas
M Abbas

Reputation: 6479

SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");

for (CreditCard cc : credit1)
    {

        out.println(cc.getNumber() + "\t");
        out.print(sf.format(cc.getExpiryDate()));

    }

Upvotes: 2

Uchenna Nwanyanwu
Uchenna Nwanyanwu

Reputation: 3204

I think you should be looking at java SimpleDateFormat.

Upvotes: 1

jrad
jrad

Reputation: 3190

You could try this:

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
String startTime = dateFormat.format(cal.getTime());

Upvotes: 1

Related Questions