當前位置: 首頁>>代碼示例>>Java>>正文


Java Calendar.get方法代碼示例

本文整理匯總了Java中java.util.Calendar.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.get方法的具體用法?Java Calendar.get怎麽用?Java Calendar.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculateRange

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public Integer[] calculateRange(String beginValue, String endValue) {
	try {
		int startPartition, endPartition;
		Calendar partitionTime = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat(dateFormat);
		partitionTime.setTime(format.parse(beginValue));
		startPartition = ((partitionTime.get(Calendar.YEAR) - beginDate.get(Calendar.YEAR))
				* 12 + partitionTime.get(Calendar.MONTH)
				- beginDate.get(Calendar.MONTH));
		partitionTime.setTime(format.parse(endValue));
		endPartition = ((partitionTime.get(Calendar.YEAR) - beginDate.get(Calendar.YEAR))
				* 12 + partitionTime.get(Calendar.MONTH)
				- beginDate.get(Calendar.MONTH));

		List<Integer> list = new ArrayList<>();

		while (startPartition <= endPartition) {
			Integer nodeValue = reCalculatePartition(startPartition);
			if (Collections.frequency(list, nodeValue) < 1)
				list.add(nodeValue);
			startPartition++;
		}
		int size = list.size();
		return (list.toArray(new Integer[size]));
	} catch (ParseException e) {
		LOGGER.error(e);
		return new Integer[0];
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:31,代碼來源:PartitionByMonth.java

示例2: getSpecifiedDayAfter

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 獲得指定日期的後一天
 * 
 * @param specifiedDay yyyy-mm-dd
 * @return
 */
public static String getSpecifiedDayAfter(String specifiedDay, SimpleDateFormat format)
{
    Calendar c = Calendar.getInstance();
    Date date = null;
    try
    {
        date = format.parse(specifiedDay);
    }
    catch (ParseException e)
    {
        e.printStackTrace();
    }
    c.setTime(date);
    int day = c.get(Calendar.DATE);
    c.set(Calendar.DATE, day + 1);
    
    String dayAfter = format.format(c.getTime());
    return dayAfter;
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:26,代碼來源:MIP_TimeUtils.java

示例3: areEqual

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public boolean areEqual(Date one, Date another) {
	if ( one == another ) {
		return true;
	}
	if ( one == null || another == null ) {
		return false;
	}

	if ( one.getTime() == another.getTime() ) {
		return true;
	}

	Calendar calendar1 = Calendar.getInstance();
	Calendar calendar2 = Calendar.getInstance();
	calendar1.setTime( one );
	calendar2.setTime( another );

	return calendar1.get( Calendar.MONTH ) == calendar2.get( Calendar.MONTH )
			&& calendar1.get( Calendar.DAY_OF_MONTH ) == calendar2.get( Calendar.DAY_OF_MONTH )
			&& calendar1.get( Calendar.YEAR ) == calendar2.get( Calendar.YEAR );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:JdbcDateTypeDescriptor.java

示例4: getTodaysHabits

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * @param date is the day that habits need to be done on
 * @return a list of habits that need to be done on the specified day
 */
public List<Habit> getTodaysHabits(Date date){
    List<Habit> list = new ArrayList<>();
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    int today = calendar.get(Calendar.DAY_OF_WEEK);

    for (Habit habit : habits){
        // don't include habits that haven't begun yet
        if (habit.occursOn(today) && !date.before(habit.getStartDate()))
            list.add(habit);
    }

    return list;
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:19,代碼來源:Profile.java

示例5: DayLabel

import java.util.Calendar; //導入方法依賴的package包/類
public DayLabel(Calendar cal){
    super(""+cal.get(Calendar.DAY_OF_MONTH), JLabel.CENTER);
    this.year = cal.get(Calendar.YEAR);
    this.month = cal.get(Calendar.MONTH);
    this.day = cal.get(Calendar.DAY_OF_MONTH);
    
    this.setFont(font);
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    if(month == calendar.get(Calendar.MONTH)) this.setForeground(java.awt.Color.BLACK);
    else this.setForeground(java.awt.Color.LIGHT_GRAY);
    
}
 
開發者ID:sivanWu0222,項目名稱:SimpleERP,代碼行數:14,代碼來源:Chooser.java

示例6: getNumber

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Parse the input string and return the corresponding calendar field
 * number.
 */
private static double getNumber(String in, String[] formats, int calField)
  throws ParseException
{
  Calendar cal = Calendar.getInstance();
  cal.setLenient(false);
  // Try the allowed formats, from longest to shortest.
  Date date = testFormats(in, formats);
  if (date == null) return Double.NaN;
  cal.setTime(date);
  return cal.get(calField);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ExsltDatetime.java

示例7: getQuarterBy

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * (季度)獲取季度份時間段內的所有季度
 * 
 * @param StartDate
 * @param endDate
 * @return
 */
public static List<String> getQuarterBy(String StartDate, String beginQ,
		String endDate, String endQ) {
	DateFormat sdf = new SimpleDateFormat("yyyy-MM");
	Date date1 = null; // 開始日期
	Date dEnd = null; // 結束日期

	try {
		date1 = sdf.parse(StartDate);
		dEnd = sdf.parse(endDate);
	} catch (ParseException e) {
		e.printStackTrace();
	}

	Calendar calBegin = Calendar.getInstance();
	// 使用給定的 Date 設置此 Calendar 的時間
	calBegin.setTime(date1);
	Calendar calEnd = Calendar.getInstance();
	// 使用給定的 Date 設置此 Calendar 的時間
	calEnd.setTime(dEnd);
	List<String> list = new ArrayList<String>();
	int beginY = calBegin.get(Calendar.YEAR);
	int beginYQ = Integer.parseInt(beginQ);
	int endY = calEnd.get(Calendar.YEAR);
	int endYQ = Integer.parseInt(endQ);
	do {
		list.add(beginY + "年第" + beginYQ + "季度");
		if (beginY == endY && beginYQ == endYQ) {
			return list;
		}
		beginYQ++;
		if (beginYQ > 4) {
			beginYQ = 1;
			beginY++;
		}
	} while (true);
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:44,代碼來源:DateUtils.java

示例8: getTime

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 獲取特定類型的時間的字符串表示
 *
 * @param type 獲取的時間類型,
 *             Types.TYPE_AM_PM:返回上午/下午/晚上
 *             Types.TYPE_MONTH_DATE:返回日期,例如2月15日
 *             Types.TYPE_CURRENT_TIME:返回時間,例如18:23
 *             其他類型:Calendar.TYPE
 * @return 類型字符串
 */
@SuppressLint("WrongConstant")
public static String getTime(int type) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    switch (type) {
        case Types.TYPE_AM_PM:
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            if (hour >= 6 && hour < 9) {
                return "早上";
            } else if (hour >= 9 && hour < 12) {
                return "上午";
            } else if (hour >= 12 && hour < 13) {
                return "中午";
            } else if (hour >= 13 && hour < 19) {
                return "下午";
            } else {
                return "晚上";
            }
        case Types.TYPE_MONTH_DATE:
            return new SimpleDateFormat("M月d日", Locale.getDefault()).format(new Date());
        case Types.TYPE_CURRENT_TIME:
            return new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date());
        case Types.TYPE_MONTH:
            return String.valueOf(calendar.get(Calendar.MONTH) + 1);
        case Types.TYPE_STRING_FORM:
            return new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date());
        default:
            return String.valueOf(calendar.get(type));
    }
}
 
開發者ID:SailFlorve,項目名稱:RunHDU,代碼行數:42,代碼來源:Utility.java

示例9: getDurations

import java.util.Calendar; //導入方法依賴的package包/類
public static Map<Integer, Duration> getDurations(CustomDuration customDuration, Long domainId) {
  // Get the durations
  Map<Integer, Duration> durations = new HashMap<Integer, Duration>();
  if (customDuration != null) {
    if (customDuration.duration != null) {
      durations.put(new Integer(customDuration.frequency), customDuration.duration);
    }
    return durations;
  }
  String timezone = DomainConfig.getInstance(domainId).getTimezone();
  // Get a day's time range (12am to 12am)
  Calendar cal = LocalDateUtil.getZeroTime(timezone);
  Duration daily = new Duration();
  cal.add(Calendar.DATE, -1);
  daily.start = cal.getTime();
  durations.put(new Integer(EventSpec.NotifyOptions.DAILY), daily); // add daily
  // Reset time to now
  cal = LocalDateUtil.getZeroTime(timezone);
  if (ConfigUtil.getBoolean("notifications.weekly", false)
      && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
    Duration weekly = new Duration();
    cal.add(Calendar.DATE, -7);
    weekly.start = cal.getTime();
    durations.put(new Integer(EventSpec.NotifyOptions.WEEKLY), weekly);
    // Reset time to now
    cal = LocalDateUtil.getZeroTime(timezone);
  }

  if (ConfigUtil.getBoolean("notifications.monthly", false)
      && cal.get(Calendar.DAY_OF_MONTH) == 1) {
    Duration monthly = new Duration();
    // Move calendar to last day of previous month
    cal.add(Calendar.MONTH, -1);
    monthly.start = cal.getTime();
    durations.put(new Integer(EventSpec.NotifyOptions.MONTHLY), monthly);
  }
  return durations;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:39,代碼來源:EventHandler.java

示例10: onCreateDialog

import java.util.Calendar; //導入方法依賴的package包/類
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);

    return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
 
開發者ID:segasunset,項目名稱:WeatherAlarmClock,代碼行數:10,代碼來源:EditAlarmActivity.java

示例11: getLastMonthLastDay

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 獲取上個月的最後第一天(最後的時刻23:59:59)
 * @return
 */
public static Date getLastMonthLastDay(){
	Calendar calendar = Calendar.getInstance();  
	int month = calendar.get(Calendar.MONTH);
	calendar.set(Calendar.MONTH, month - 1);
	calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
	calendar.set(Calendar.HOUR_OF_DAY,23);
	calendar.set(Calendar.SECOND,59);
	calendar.set(Calendar.MINUTE,59);
	calendar.set(Calendar.MILLISECOND,0);
	return calendar.getTime();  
}
 
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:16,代碼來源:DateKit.java

示例12: getSmartBirthday

import java.util.Calendar; //導入方法依賴的package包/類
/**獲取智能生日
 * @param birthday
 * @param needYear
 * @return
 */
public static String getSmartBirthday(long birthday, boolean needYear) {
	int[] birthdayDetails = getDateDetail(birthday);
	int[] nowDetails = getDateDetail(System.currentTimeMillis());

	Calendar birthdayCalendar = Calendar.getInstance();
	birthdayCalendar.set(birthdayDetails[0], birthdayDetails[1], birthdayDetails[2]);

	Calendar nowCalendar = Calendar.getInstance();
	nowCalendar.set(nowDetails[0], nowDetails[1], nowDetails[2]);

	int days = birthdayCalendar.get(Calendar.DAY_OF_YEAR) - nowCalendar.get(Calendar.DAY_OF_YEAR);
	if (days < 8) {
		if (days >= 3) {
			return days + "天後";
		}
		if (days >= 2) {
			return TimeUtil.Day.NAME_THE_DAY_AFTER_TOMORROW;
		}
		if (days >= 1) {
			return TimeUtil.Day.NAME_TOMORROW;
		}
		if (days >= 0) {
			return TimeUtil.Day.NAME_TODAY;
		}
	}

	if (needYear) {
		return birthdayDetails[0] + "年" + birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
	} 
	return birthdayDetails[1] + "月" + birthdayDetails[2] + "日";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:TimeUtil.java

示例13: getWeek

import java.util.Calendar; //導入方法依賴的package包/類
private String getWeek(String pTime) {
    String Week = "";
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(format.parse(pTime));
    } catch (ParseException e) {
        return null;
    }
    switch (c.get(Calendar.DAY_OF_WEEK)){
        case Calendar.SUNDAY:
            Week = "周日";
            break;
        case Calendar.MONDAY:
            Week = "周一";
            break;
        case Calendar.TUESDAY:
            Week = "周二";
            break;
        case Calendar.WEDNESDAY:
            Week = "周三";
            break;
        case Calendar.THURSDAY:
            Week = "周四";
            break;
        case Calendar.FRIDAY:
            Week = "周五";
            break;
        case Calendar.SATURDAY:
            Week = "周六";
            break;
    }
    return Week;
}
 
開發者ID:xfangfang,項目名稱:NeuTV,代碼行數:35,代碼來源:Video.java

示例14: formatTimeWithDayIfNotToday

import java.util.Calendar; //導入方法依賴的package包/類
public static String formatTimeWithDayIfNotToday(Context context, long timeInMillis) {
    Calendar now = Calendar.getInstance();
    Calendar lastCheckedCal = new GregorianCalendar();
    lastCheckedCal.setTimeInMillis(timeInMillis);
    Date lastCheckedDate = new Date(timeInMillis);
    String timeFormat = android.text.format.DateFormat.getTimeFormat(context).format(lastCheckedDate);
    if (now.get(Calendar.YEAR) == lastCheckedCal.get(Calendar.YEAR) &&
            now.get(Calendar.DAY_OF_YEAR) == lastCheckedCal.get(Calendar.DAY_OF_YEAR)) {
        // Same day, only show time
        return timeFormat;
    } else {
        return android.text.format.DateFormat.getDateFormat(context).format(lastCheckedDate) + " " + timeFormat;
    }
}
 
開發者ID:hichemcesar24,項目名稱:Weather-Android,代碼行數:15,代碼來源:MainActivity.java

示例15: getMinuteFromMillis

import java.util.Calendar; //導入方法依賴的package包/類
public static int getMinuteFromMillis(long timeInMillis) {
    final Calendar auxCalendar = Calendar.getInstance();
    auxCalendar.setTimeInMillis(timeInMillis);
    return auxCalendar.get(Calendar.MINUTE);
}
 
開發者ID:GrenderG,項目名稱:Protestr,代碼行數:6,代碼來源:TimeUtils.java


注:本文中的java.util.Calendar.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。