Java Code Examples for java.time.LocalDateTime#plusWeeks()

The following examples show how to use java.time.LocalDateTime#plusWeeks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePlusWeeks.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void add_weeks_to_date_in_java8() {

	LocalDateTime xmas = LocalDateTime.of(2012, Month.DECEMBER, 25, 0, 0);
	LocalDateTime newYearsDay = xmas.plusWeeks(1);

	java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter
			.ofPattern("MM/dd/yyyy HH:mm:ss S");

	logger.info(xmas.format(formatter));
	logger.info(newYearsDay.format(formatter));

	assertTrue(newYearsDay.isAfter(xmas));
}
 
Example 2
Source File: DateUtils.java    From Lottor with MIT License 4 votes vote down vote up
/**
 * 获得当天近一周
 * @return LocalDateTime
 */
public static LocalDateTime getAWeekFromNow() {
    LocalDateTime date = LocalDateTime.now();
    //7天前
    return date.plusWeeks(-1);
}
 
Example 3
Source File: DateUtils.java    From Raincat with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 获得当天近一周.
 *
 * @return 日期 a week from now
 */
public static LocalDateTime getAWeekFromNow() {
    LocalDateTime date = LocalDateTime.now();
    //7天前
    return date.plusWeeks(-1);
}
 
Example 4
Source File: 11947 Cancer or Scorpio.java    From UVA with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	int [][] range={{1,21,2,19},
					{2,20,3,20},
					{3,21,4,20},
					{4,21,5,21},
					{5,22,6,21},
					{6,22,7,22},
					{7,23,8,21},
					{8,22,9,23},
					{9,24,10,23},
					{10,24,11,22},
					{11,23,12,22},
					{12,23,12,31},
					{1,1,1,20}};
	String [] rangeName={"aquarius","pisces","aries","taurus","gemini","cancer","leo","virgo","libra","scorpio","sagittarius","capricorn","capricorn"};
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int testCaseCount=Integer.parseInt(br.readLine());
	for (int testCase=1;testCase<=testCaseCount;testCase++) {
		String s=br.readLine();
		LocalDateTime dt=LocalDateTime.of(Integer.parseInt(s.substring(4,8)),Integer.parseInt(s.substring(0,2)),Integer.parseInt(s.substring(2,4)),0,0);
		dt=dt.plusWeeks(40);
		int d=dt.getDayOfMonth();
		int m=dt.getMonthValue();
		int i=0;
		for (;i<range.length;i++) {
			if ((m==range[i][0] && d>=range[i][1]) || (m==range[i][2] && d<=range[i][3]))  {
				break;
			}
		}
		StringBuilder sb=new StringBuilder();
		sb.append(testCase);
		sb.append(" ");
		if (m<10) {
			sb.append("0");
		}
		sb.append(m);
		sb.append("/");
		if (d<10) {
			sb.append("0");
		}
		sb.append(d);
		sb.append("/");
		sb.append(dt.getYear());
		sb.append(" ");
		sb.append(rangeName[i]);
		System.out.println(sb.toString());
	}
}