java.time.DayOfWeek的minus()方法是Java中的一个内置函数,该函数使用一个长整数作为参数,并在按传递的参数指定的前进或后退几天后返回DayOfWeek的实例。计算从星期一到星期日的一周结束时进行。指定的时间段可以是正数或负数。
方法声明:
public DayOfWeek minus(long days)
用法:
DayOfWeek dayOfWeekObject = dayOfWeekObject.minus(long days)
参数:此方法以天为参数,其中:
- days–是前进或后退的天数。
- dayOfWeekObject–是DayOfWeek对象的实例。
返回值:向后或向前前进几天后,该函数将返回DayOfWeek的实例。
以下示例程序旨在说明上述方法:
示例1:
// Java Program Demonstrate minus()
// method of DayOfWeek
import java.time.DayOfWeek;
class DayOfWeekExample {
public static void main(String[] args)
{
// Getting an instance of DayOfWeek from int value
DayOfWeek dayOfWeek = DayOfWeek.of(2);
// Printing the day of the week and its Int value
System.out.println("Day of the Week : "
+ dayOfWeek.name() + " - "
+ dayOfWeek.getValue());
// Number of days to advance
long adv = 10;
// Advancing the day
dayOfWeek = dayOfWeek.minus(adv);
// Printing the day of the week and its
// Int value before adv days
System.out.println("Day of the Week before "
+ adv + " days: "
+ dayOfWeek.name() + " - "
+ dayOfWeek.getValue());
}
}
输出:
Day of the Week : TUESDAY - 2 Day of the Week before 10 days: SATURDAY - 6
示例2:
// Java Program Demonstrate minus()
// method of DayOfWeek
import java.time.DayOfWeek;
class DayOfWeekExample {
public static void main(String[] args)
{
// Getting an instance of DayOfWeek
// from int value
DayOfWeek dayOfWeek = DayOfWeek.of(7);
// Printing the day of the week
// and its Int value
System.out.println("Day of the Week : "
+ dayOfWeek.name()
+ " - "
+ dayOfWeek.getValue());
// Number of days to advance
long adv = -3;
// Advancing the day
dayOfWeek = dayOfWeek.minus(adv);
// Printing the day of the week and its
// Int value before adv days
System.out.println("Day of the Week before "
+ adv + " days: "
+ dayOfWeek.name()
+ " - "
+ dayOfWeek.getValue());
}
}
输出:
Day of the Week : SUNDAY - 7 Day of the Week before -3 days: WEDNESDAY - 3
参考: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#minus-long-
相关用法
- Java DayOfWeek from()用法及代码示例
- Java DayOfWeek get()用法及代码示例
- Java DayOfWeek of()用法及代码示例
- Java DayOfWeek plus()用法及代码示例
- Java DayOfWeek getValue()用法及代码示例
- Java DayOfWeek getDisplayName()用法及代码示例
- Java WeekFields dayOfWeek()用法及代码示例
- Java DayOfWeek valueOf()用法及代码示例
- Java DayOfWeek adjustInto()用法及代码示例
- Java DayOfWeek values()用法及代码示例
- Java OffsetTime minus()用法及代码示例
- Java LocalDate minus()用法及代码示例
- Java LocalDateTime minus()用法及代码示例
- Java Period minus()用法及代码示例
- Java Instant minus()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 DayOfWeek minus() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。