List of usage examples for java.util Calendar set
public final void set(int year, int month, int date)
YEAR
, MONTH
, and DAY_OF_MONTH
. From source file:MainClass.java
public static void main(String args[]) throws Exception { X509CertSelector selec = new X509CertSelector(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(args[0]); Certificate c = cf.generateCertificate(in); System.out.println(selec.match(c)); selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN"); System.out.println(selec.match(c)); Calendar cld = Calendar.getInstance(); int year = Integer.parseInt(args[1]); int month = Integer.parseInt(args[2]) - 1; int day = Integer.parseInt(args[3]); cld.set(year, month, day); Date d = cld.getTime();/*from ww w . ja v a2 s . co m*/ selec.setCertificateValid(d); System.out.println(selec.match(c)); BigInteger sn = new BigInteger("1039056963"); selec.setSerialNumber(sn); System.out.println(selec.match(c)); }
From source file:com.glaf.core.job.SysDataLogCreateTableJob.java
public static void main(String[] args) { Date date = DateUtils.getDateAfter(new Date(), 0); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// w ww. ja v a 2 s . c om int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int daysOfMonth = DateUtils.getYearMonthDays(year, month + 1); calendar.set(year, month, daysOfMonth); int begin = getYearMonthDay(date); int end = getYearMonthDay(calendar.getTime()); for (int i = begin; i <= end; i++) { logger.debug(i); try { SysDataLogTableUtils.createTable("SYS_DATA_LOG_" + i); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } } }
From source file:com.glaf.core.util.DateUtils.java
public static void main(String[] args) { System.out.println(DateUtils.getDate(new Date())); System.out.println(DateUtils.getDateTime(new Date())); System.out.println(DateUtils.getYearMonthDay(new Date())); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); calendar.set(year, month, day - 7); Date dateBefore = calendar.getTime(); System.out.println("day:" + year + "-" + month + "-" + day); System.out.println(DateUtils.getDate(dateBefore)); calendar.set(year - 1, month, day);/* www . ja va2 s. com*/ dateBefore = calendar.getTime(); System.out.println(DateUtils.getDate(dateBefore)); calendar.set(year, month - 15, day); dateBefore = calendar.getTime(); System.out.println(">>" + DateUtils.getDate(dateBefore)); calendar.set(year, month, day - 365); dateBefore = calendar.getTime(); System.out.println(">>>>" + DateUtils.getDate(dateBefore)); String[] parsePatterns = { DateUtils.DATE_TIME_PATTERN, DateUtils.DATE_PATTERN }; System.out.println(DateUtils.parseDate("2009-12-25", parsePatterns)); System.out.println(DateUtils.parseDate("2009-12-25 12:00:05", parsePatterns)); System.out.println(DateUtils.parseDate("2009-12-25 23:59:59", parsePatterns)); System.out.println(DateUtils.parseDate("2009-12-25 00:00:00", parsePatterns)); System.out.println(Locale.getDefault()); System.out.println(DateUtils.toDate("2009")); System.out.println(DateUtils.toDate("2009-12")); System.out.println(DateUtils.toDate("2009-12-25")); System.out.println(DateUtils.toDate("2009-12-25 13")); System.out.println(DateUtils.toDate("2009-12-25 10:45")); System.out.println(DateUtils.toDate("2009-12-25 22:45:50")); System.out.println(dateDiff(DateUtils.toDate("2013-10-25"), DateUtils.toDate("2013-10-29"))); Date toDate = DateUtils.getDateAfter(DateUtils.toDate("2013-03-21"), 60); System.out.println(getDateTime(toDate)); long daysDiff = DateUtils.dateDiff(new Date(), toDate); System.out.println(daysDiff); System.out.println(DateUtils.getYearDays(2015)); }
From source file:GenAppStoreSales.java
/** * Starting point for the demonstration application. * @throws IOException /*from w w w . j a va 2s. c o m*/ * */ public static void main(String[] args) throws IOException { System.out.print("\nRefreshing Apple Store Reports..."); // Init Calendars rollCalendar = Calendar.getInstance(); updateRollCalendar(); currentYear = rollCalendar.get(Calendar.YEAR); currentMonth = rollCalendar.get(Calendar.MONTH) + 1; currentDay = rollCalendar.get(Calendar.DATE); Calendar launchCalendar = Calendar.getInstance(); int launchYear = 2013, launchMonth = 2, launchDay = 28; //Month from 0..11 launchCalendar.set(launchYear, launchMonth, launchDay); /* Report Folders */ currentPath = new File("").getAbsolutePath(); String sourceName = "/sources"; File sourceDir = new File(currentPath, sourceName); if (!sourceDir.isDirectory()) { if (!(new File(currentPath + sourceName)).mkdirs()) { System.out.println("[Error] Couldn't create 'source' folder."); } } sourcePath = sourceDir.getAbsolutePath(); String chartName = "/charts"; File chartDir = new File(currentPath, chartName); if (!chartDir.isDirectory()) { if (!(new File(currentPath + chartName)).mkdirs()) { System.out.println("[Error] Couldn't create 'chart' folder."); } } chartPath = chartDir.getAbsolutePath(); String dateCode, reportName; // DAILY REPORT System.out.println("\n-> Daily reports"); for (int d = 0; d < 14; d++) { rollCalendar.add(Calendar.DATE, -1); if (rollCalendar.compareTo(launchCalendar) <= 0) break; updateRollCalendar(); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); reportName = "S_D_" + appID + "_" + dateCode + ".txt"; autoingestionDownload(reportName, "Daily", dateCode); } printDatePeriod("DAILY", "report"); // WEEKLY REPORT System.out.println("\n-> Weekly reports"); rollCalendar = Calendar.getInstance(); rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); pursuedDay = currentDay; pursuedMonth = currentMonth; pursuedYear = currentYear; for (int w = 0; w < 13; w++) { rollCalendar.add(Calendar.DATE, -7); if (rollCalendar.compareTo(launchCalendar) <= 0) break; updateRollCalendar(); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); reportName = "S_W_" + appID + "_" + dateCode + ".txt"; autoingestionDownload(reportName, "Weekly", dateCode); } printDatePeriod("WEEKLY", "report"); // MONTHLY REPORTS System.out.println("\n-> Monthly reports"); rollCalendar = Calendar.getInstance(); pursuedDay = currentDay; pursuedMonth = currentMonth - 1; pursuedYear = currentYear; for (int m = 0; m < 12; m++) { rollCalendar.add(Calendar.MONTH, -1); rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); if (rollCalendar.compareTo(launchCalendar) <= 0) break; updateRollCalendar(); dateCode = String.format("%d%02d", pursuedYear, pursuedMonth); reportName = "S_M_" + appID + "_" + dateCode + ".txt"; autoingestionDownload(reportName, "Monthly", dateCode); } printDatePeriod("MONTHLY", "report"); // YEARLY REPORTS System.out.println("\n-> Yearly reports"); rollCalendar = Calendar.getInstance(); rollCalendar.add(Calendar.DATE, -1); pursuedDay = currentDay - 1; pursuedMonth = currentMonth; pursuedYear = currentYear; for (int y = 0; y < 100; y++) { rollCalendar.add(Calendar.YEAR, -1); if (rollCalendar.compareTo(launchCalendar) <= 0) break; updateRollCalendar(); dateCode = String.format("%d", pursuedYear); reportName = "S_Y_" + appID + "_" + dateCode + ".txt"; autoingestionDownload(reportName, "Yearly", dateCode); } printDatePeriod("YEARLY", "report"); /** * Reading Sales.txt & Generating Charts */ // WEEK CHARTS String plotName, pursuedPeriodDate; System.out.print("\nRestoring charts...\n"); System.out.println("-> Week charts"); rollCalendar = Calendar.getInstance(); rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); rollCalendar.add(Calendar.DATE, -7); updateRollCalendar(); while (rollCalendar.compareTo(launchCalendar) > 0) { pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); plotName = "S_W_" + appID + "_" + dateCode; File plotFile = new File(chartPath + "/" + plotName + ".png"); if (!plotFile.isFile()) { readSales("week", true, true); if (countryLabels.size() > 0) { genPlot("WEEK", plotName, pursuedPeriodDate, countryLabels, countryUnits); } if (countryInAppLabels.size() > 0) { genPlot("WEEK IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits); } } else readSales("week", false, true);// Week already plotted } printDatePeriod("WEEK", "charts"); // Incomplete current Week (let the current day be computed) rollCalendar = Calendar.getInstance(); updateRollCalendar(); readSales("week", false, true); // MONTH CHARTS System.out.println("\n-> Month charts"); rollCalendar = Calendar.getInstance(); rollCalendar.add(Calendar.MONTH, -1); rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); updateRollCalendar(); while (rollCalendar.compareTo(launchCalendar) > 0) { pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); plotName = "S_M_" + appID + "_" + dateCode; File plotFile = new File(chartPath + "/" + plotName + ".png"); if (!plotFile.isFile()) { readSales("month", true, false); if (countryLabels.size() > 0) { genPlot("MONTH", plotName, pursuedPeriodDate, countryLabels, countryUnits); } if (countryInAppLabels.size() > 0) { genPlot("MONTH", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits); } } else { readSales("month", false, false); } } printDatePeriod("MONTH", "charts"); // YEAR CHARTS System.out.println("\n-> Year charts"); rollCalendar = (Calendar) launchCalendar.clone(); rollCalendar.set(Calendar.DATE, -1); rollCalendar.add(Calendar.YEAR, -1); updateRollCalendar(); while (rollCalendar.compareTo(launchCalendar) > 0) { pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); plotName = "S_Y_" + appID + "_" + dateCode; File plotFile = new File(chartPath + "/" + plotName + ".png"); if (!plotFile.isFile()) { readSales("year", true, false); if (countryLabels.size() > 0) { genPlot("YEAR", plotName, pursuedPeriodDate, countryLabels, countryUnits); } if (countryInAppLabels.size() > 0) { genPlot("YEAR", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits); } } else readSales("year", false, false); } printDatePeriod("YEAR", "charts"); // CUSTOM CHART PERIOD System.out.println("\n-> Custom charts"); customCalendar = (Calendar) launchCalendar.clone(); // begin day rollCalendar = Calendar.getInstance(); // end day rollCalendar.add(Calendar.DATE, -1); updateRollCalendar(); pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear); dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); plotName = "S_C_" + appID + "__whole";// + dateCode; File plotFile = new File(chartPath + "/" + plotName + ".png"); if (!plotFile.isFile()) { readSales("custom", true, false); if (countryLabels.size() > 0) { genPlot("CUSTOM", plotName, pursuedPeriodDate, countryLabels, countryUnits); } if (countryInAppLabels.size() > 0) { genPlot("CUSTOM IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits); } } printDatePeriod("CUSTOM Period", "charts"); // Day Sales units rollCalendar = Calendar.getInstance(); rollCalendar.add(Calendar.DATE, -1); updateRollCalendar(); readSales("day", false, false); System.out.println("\nTotal units: " + totalUnits + "/" + totalUpdateUnits + "-Up (+" + dayUnits + ")"); System.out.println("Total IN-APP units: " + totalInAppUnits + " (+" + dayINAPPUnits + ")\n"); System.exit(0); }
From source file:Main.java
public static String getDateString(int year, int month, int day) { Calendar c = Calendar.getInstance(); c.set(year, month, day); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(c.getTime()); }
From source file:Main.java
public static int getDayOfMaonth(int y, int m) { Calendar cal = Calendar.getInstance(); cal.set(y, m - 1, 1); int dateOfMonth = cal.getActualMaximum(Calendar.DATE); return dateOfMonth; }
From source file:Main.java
public static int getDayOfMonth(int y, int m) { Calendar cal = Calendar.getInstance(); cal.set(y, m - 1, 1); int dateOfMonth = cal.getActualMaximum(Calendar.DATE); return dateOfMonth; }
From source file:Main.java
public static int getMonthOfMonth(int y, int m) { Calendar cal = Calendar.getInstance(); cal.set(y, m - 1, 1); int dateOfMonth = cal.get(Calendar.MONTH); return dateOfMonth + 1; }
From source file:Main.java
public static int getWeekdayOfFirstDayOfMonth(int year, int month) { int dayOfWeek = -1; Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, 1); dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); return dayOfWeek - 1; }
From source file:Main.java
public static long getTimeLong(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); return calendar.getTimeInMillis(); }