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 8735787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:09:08+00:00 2026-06-13T10:09:08+00:00

need help, how to convert this in java? 09-09-2012 = September 9, 2012? our

  • 0

need help, how to convert this in java? 09-09-2012 = September 9, 2012?
our instructor give it as an assignment.. Month, day, and year and inputted using separately

thnx in advance

package exam4;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;

public class Exam4 {

public static void main(String[] args) {


        String inMonth=JOptionPane.showInputDialog(null, "Enter Month");
            int intMonth = Integer.parseInt(inMonth);

        String inDay=JOptionPane.showInputDialog(null, "Enter Day");
            int intDay = Integer.parseInt(inDay);

        String inYear=JOptionPane.showInputDialog(null, "Enter Year");
            int intYear = Integer.parseInt(inYear);

        getDate(intMonth, intDay, intYear);


}

static void getDate(int intMonth, int intDay, int intYear){

    if((intMonth==2)&&(intDay<=29)&&(intYear<=9999)){
        JOptionPane.showMessageDialog(null, "February 29, 2012");
        genDate(intMonth,intDay,intYear);
    }         

        else if (((intMonth<12)&&(intDay<31)&&(intYear<9999))&&((intMonth==2)&&(intDay<=29)&&(intYear<=9999))){
            JOptionPane.showMessageDialog(null, "Regular date");

        }

        else{
            JOptionPane.showMessageDialog(null, "atik na date");
        }
}

static void genDate(int intMonth, int intDay, int intYear){

        String fMonth = Integer.toString(intMonth);
        String fDay = Integer.toString(intDay);
        String fYear = Integer.toString(intYear);

        String DateTime=fMonth+fDay+fYear;

    SimpleDateFormat dateFormat = new SimpleDateFormat("MMddyyyy");
    Date myDate = null;

        try {
            myDate = dateFormat.parse(DateTime);
        } catch (ParseException e) {
          }

    SimpleDateFormat timeFormat = new SimpleDateFormat("MMMMM dd, yyyy");
    String finalDate = timeFormat.format(myDate);

    JOptionPane.showMessageDialog(null,finalDate);

} 

}

when i inputted the 02 02 2012, it gives me weird date… try to enter 02 29 2012.. and it gives december 13, 0013.. i dnt knw why =(

  • 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-06-13T10:09:10+00:00Added an answer on June 13, 2026 at 10:09 am

    Use SimpleDateFormat to convert the string to date and then convert back to String as below:

         DateFormat format1 = new SimpleDateFormat("MM-dd-yyyy");
         Date date = format1.parse("09-09-2012");
         DateFormat format2 = new SimpleDateFormat("MMMMM dd, yyyy");
         String dateString = format2.format(date);
         System.out.println(dateString); //<- prints September 09, 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Gain datatype date with year and month Problem: Need to help to convert
Please i need someone to help convert this query entity(c#) form. select * from
I am trying to convert this to python. I just really need help with
I need to convert this java code in force.com apex. i tried to use
I need to convert the function path::combine(path1, path2). Please help me if you have
I have an HTML help system that I need to convert to SharePoint. The
I need to convert my customized objects to native Java Object. My Object structure
I have this code in Java and I want to convert it to C#.
I have a java.awt.Image that I need to add CCITT T.6 compression and convert
Kindly need your help as this really taking me long time to try. From

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.