当前位置: 首页>>代码示例>>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;未经允许,请勿转载。