本文整理汇总了Java中java.util.Calendar.WEEK_OF_MONTH属性的典型用法代码示例。如果您正苦于以下问题:Java Calendar.WEEK_OF_MONTH属性的具体用法?Java Calendar.WEEK_OF_MONTH怎么用?Java Calendar.WEEK_OF_MONTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.WEEK_OF_MONTH属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeRelativeTo
public long getTimeRelativeTo(long time)
{
int valueToUse = -(int) value;
int field = 0;
if (getUnit() == TimeUnit.MILLISECONDS)
{
field = Calendar.MILLISECOND;
//we do our own adjustment as calendar cannot handle a long.
time -= value;
valueToUse = 0;
}
else if (getUnit() == TimeUnit.SECONDS)
field = Calendar.SECOND;
else if (getUnit() == TimeUnit.MINUTES)
field = Calendar.MINUTE;
else if (getUnit() == TimeUnit.HOURS)
field = Calendar.HOUR;
else if (getUnit() == TimeUnit.DAYS)
field = Calendar.DATE;
else if (getUnit() == TimeUnit.WEEKS)
field = Calendar.WEEK_OF_MONTH;
else if (getUnit() == TimeUnit.MONTHS)
field = Calendar.MONTH;
else if (getUnit() == TimeUnit.YEARS)
field = Calendar.YEAR;
calendar.setTimeInMillis(time);
calendar.add(field, valueToUse);
return calendar.getTime().getTime();
}
示例2: getFutureTimeRelativeTo
public long getFutureTimeRelativeTo(long time)
{
int valueToUse = (int) value;
int field = 0;
if (getUnit() == TimeUnit.MILLISECONDS)
{
field = Calendar.MILLISECOND;
//we do our own adjustment as calendar cannot handle a long.
time += value;
valueToUse = 0;
}
else if (getUnit() == TimeUnit.SECONDS)
field = Calendar.SECOND;
else if (getUnit() == TimeUnit.MINUTES)
field = Calendar.MINUTE;
else if (getUnit() == TimeUnit.HOURS)
field = Calendar.HOUR;
else if (getUnit() == TimeUnit.DAYS)
field = Calendar.DATE;
else if (getUnit() == TimeUnit.WEEKS)
field = Calendar.WEEK_OF_MONTH;
else if (getUnit() == TimeUnit.MONTHS)
field = Calendar.MONTH;
else if (getUnit() == TimeUnit.YEARS)
field = Calendar.YEAR;
calendar.setTimeInMillis(time);
calendar.add(field, valueToUse);
return calendar.getTime().getTime();
}