Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Locale;
- import java.util.Scanner;
- public class ParseDate {
- private Calendar calendar;
- private DateFormat df;
- public ParseDate(String date) {
- Date sd = null;
- try {
- sd = new SimpleDateFormat("yyyy-MM-dd").parse(date);
- }
- catch (Exception e) {
- }
- calendar = Calendar.getInstance(Locale.JAPAN);
- calendar.setTime(sd);
- df = DateFormat.getDateInstance(DateFormat.FULL, Locale.JAPAN);
- }
- public Calendar getCalendar() {
- return calendar;
- }
- public String getWeek() {
- int week = calendar.get(Calendar.DAY_OF_WEEK);
- if (week == Calendar.MONDAY) return "Monday";
- if (week == Calendar.TUESDAY) return "Tuesday";
- if (week == Calendar.WEDNESDAY) return "Wednesday";
- if (week == Calendar.THURSDAY) return "Thursday";
- if (week == Calendar.FRIDAY) return "Friday";
- if (week == Calendar.SATURDAY) return "Saturday";
- return "Sunday";
- }
- public void add(int days) {
- calendar.add(Calendar.DATE, days);
- }
- @Override
- public String toString() {
- return df.format(calendar.getTime());
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- ParseDate p = new ParseDate(in.next());
- System.out.println(p);
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement