标签:一点 gettime void pre range cloud rgs java tin
package com.cloudmap.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class testCalender2 { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH)+1; int day = calendar.get(Calendar.DATE); int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); System.out.println(year); System.out.println(month); System.out.println(day); System.out.println(hour); System.out.println(minute); System.out.println(second); //获取当前时间的起始周日期以及结束周日期,以及前几周或后几周 int i = 0; //printWeekStartAndEnd(i); //获取当前日期本年的第多少周 //printWeekOfYear(); } private static void printWeekOfYear() { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(new Date()); System.out.println(calendar.get(Calendar.WEEK_OF_YEAR)); } private static void printWeekStartAndEnd(int i) { Calendar calendarRange = Calendar.getInstance(); calendarRange.setTime(new Date()); calendarRange.add(Calendar.DAY_OF_YEAR,i); int currentDay = calendarRange.get(Calendar.DAY_OF_WEEK); if (currentDay == 1) { currentDay = 7; } else { currentDay = currentDay - 1; } calendarRange.add(Calendar.DAY_OF_YEAR, 1 - currentDay); Date dateRange = calendarRange.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String weekStart = format.format(dateRange); System.out.println(weekStart); calendarRange.setTime(dateRange); calendarRange.add(Calendar.DAY_OF_YEAR, 6); String weekEnd = format.format(calendarRange.getTime()); System.out.println(weekEnd); } }
标签:一点 gettime void pre range cloud rgs java tin
原文地址:https://www.cnblogs.com/notchangeworld/p/11663063.html