HuyPV
Thursday, September 9, 2010
import java.util.*;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
class MyDate {
public static void main(String args[]) throws Exception {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
DateFormat fdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date billMonth = new Date();
System.out.println(fdf.format(billMonth));
Calendar cld = Calendar.getInstance();
cld.setTime(billMonth);
cld.add(Calendar.MONTH, 1); // Calendar.MONTH = 2
System.out.println("1 month later: \n" + fdf.format(cld.getTime()));
try {
Date myday = df.parse("10/10/2010");
System.out.println(fdf.format(myday));
} catch (ParseException e) {
e.printStackTrace();
}
int month = new Date().getMonth() + 1, year = new Date().getYear() + 1900;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("Enter month: ");
month = Integer.valueOf(br.readLine());
System.out.print("Enter year: ");
year = Integer.valueOf(br.readLine());
} catch (IOException ioe) {
System.out.println("IO error trying to read your name!");
System.exit(1);
}
Date myday = df.parse("1/" +String.valueOf(month)+ "/" + String.valueOf(year));
cld.setTime(myday);
System.out.println(String.valueOf(myday.getMonth() + 1)+ "/" + String.valueOf(myday.getYear() + 1900) + ": has " + String.valueOf(cld.getActualMaximum(Calendar.DAY_OF_MONTH)) + " days");
}
}
Title:
Java Date DateFormat String DAY_OF_MONTH
Description:
import java.util.*; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.text.ParseException; ...
...
Rating:
4