Java Calendar Create getCalendar(String time, char sep, boolean isStart)

Here you can find the source of getCalendar(String time, char sep, boolean isStart)

Description

get Calendar

License

Open Source License

Declaration

public static Calendar getCalendar(String time, char sep, boolean isStart) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {

    public static Calendar getCalendar(String time, char sep, boolean isStart) {
        Calendar cal = Calendar.getInstance();

        cal.set(Calendar.HOUR_OF_DAY, isStart ? 0 : 23);
        cal.set(Calendar.MINUTE, isStart ? 0 : 59);
        cal.set(Calendar.SECOND, isStart ? 0 : 59);
        cal.set(Calendar.MILLISECOND, isStart ? 0 : 999);

        try {/* w w  w .  j  a v  a  2s.  co m*/
            int idx = time.indexOf(sep);

            if (idx != -1) {
                cal.set(Calendar.YEAR, Integer.parseInt(time.substring(0, idx)));
                time = time.substring(idx + 1);
                idx = time.indexOf(sep);
                if (idx != -1) {
                    cal.set(Calendar.MONTH, Integer.parseInt(time.substring(0, idx)) - 1);
                    cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(time.substring(idx + 1)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return cal;
    }
}

Related

  1. getCalendar(String date)
  2. getCalendar(String dateStr, int inputYearType, int outputYearType)
  3. getCalendar(String dateString)
  4. getCalendar(String gdate)
  5. getCalendar(String str)
  6. getCalendar(String yyyy, String mm, String dd)
  7. getCalendar(TimeZone timeZone, Locale locale)
  8. getCalendarAtMidnight(Date d)
  9. getCalendarBefore(int i)