List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398FellowshipSupplementalV1_1Generator.java
private ScaleTwoDecimal getNumberOfMonths(Date dateStart, Date dateEnd) { BigDecimal monthCount = ScaleTwoDecimal.ZERO.bigDecimalValue(); int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart);//from ww w. ja va2 s .c o m endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = new ScaleTwoDecimal(startMonthDays).bigDecimalValue() .divide(new ScaleTwoDecimal(startMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = new ScaleTwoDecimal(endMonthDays).bigDecimalValue() .divide(new ScaleTwoDecimal(endMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount).bigDecimalValue()).add(startMonthFraction) .add(endMonthFraction); return new ScaleTwoDecimal(monthCount); }
From source file:com.concursive.connect.web.modules.documents.dao.FileItem.java
/** * For temporary UI entries, this unique value can be used for file selector * * @return date based unique value/* w w w . java 2s.c o m*/ */ public static String createUniqueValue() { Calendar cal = Calendar.getInstance(); return (String.valueOf(cal.get(Calendar.HOUR)) + String.valueOf(cal.get(Calendar.MINUTE)) + String.valueOf(cal.get(Calendar.SECOND)) + String.valueOf(cal.get(Calendar.MILLISECOND))); }
From source file:com.okta.tools.awscli.java
private static void resultMessage(String profileName) { Calendar date = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat(); date.add(Calendar.HOUR, 1); //change with file customization System.out.println(//from www . ja v a 2 s.co m "\n----------------------------------------------------------------------------------------------------------------------"); System.out.println( "Your new access key pair has been stored in the aws configuration file with the following profile name: " + profileName); System.out.println( "The AWS Credentials file is located in " + System.getProperty("user.home") + "/.aws/credentials."); System.out.println("Note that it will expire at " + dateFormat.format(date.getTime())); System.out.println("After this time you may safely rerun this script to refresh your access key pair."); System.out.println("To use these credentials, please call the aws cli with the --profile option " + "(e.g. aws --profile " + profileName + " ec2 describe-instances)"); System.out.println( "You can also omit the --profile option to use the last configured profile " + "(e.g. aws s3 ls)"); System.out.println( "----------------------------------------------------------------------------------------------------------------------"); }
From source file:com.topsec.tsm.sim.report.util.ReportUiUtil.java
/** * /*from w w w. j a v a 2 s.c om*/ * ?[] * * @param String * ruleDate [] * * @return Date * */ public static Date getAddDate(String ruleDate) { Calendar rightNow = Calendar.getInstance(); if (ruleDate.equals("addHour")) rightNow.add(Calendar.HOUR, -1); else if (ruleDate.equals("addDay") || ruleDate.equalsIgnoreCase("day") || ruleDate.equals("lable.report.typeday") || "lable.report.typedayReportType".equals(ruleDate)) { rightNow.add(Calendar.DATE, -1); } else if (ruleDate.equals("addMonth") || ruleDate.equalsIgnoreCase("month") || ruleDate.equals("lable.report.typemonth") || "lable.report.typemonthReportType".equals(ruleDate)) rightNow.add(Calendar.MONTH, -1); else if (ruleDate.equalsIgnoreCase("week") || ruleDate.equals("lable.report.week") || "lable.report.weekReportType".equals(ruleDate)) { Date now = rightNow.getTime(); rightNow.set(Calendar.DAY_OF_WEEK, 2); //rightNow ? Date monday = rightNow.getTime(); if (now.getTime() < monday.getTime()) { rightNow.set(Calendar.MINUTE, -10080); // } } else if (ruleDate.equalsIgnoreCase("year") || ruleDate.equals("lable.report.typeyear") || "lable.report.typeyearReportType".equals(ruleDate)) rightNow.add(Calendar.YEAR, -1); else if (ruleDate.equals("minute")) rightNow.add(Calendar.MINUTE, 2); return rightNow.getTime(); }
From source file:com.ikanow.infinit.e.core.mapreduce.HadoopJobRunner.java
/** * Uses a map reduce jobs schedule frequency to determine when the next * map reduce job should be ran./*from ww w . ja v a2s.c o m*/ * * @param scheduleFreq * @param firstSchedule * @param iterations * @return */ private long getNextRunTime(SCHEDULE_FREQUENCY scheduleFreq, Date firstSchedule, long nextRuntime, int iterations) { if (null == firstSchedule) { firstSchedule = new Date(nextRuntime); iterations = 1; // recover... } if (scheduleFreq == null || SCHEDULE_FREQUENCY.NONE == scheduleFreq) { return Long.MAX_VALUE; } Calendar cal = new GregorianCalendar(); cal.setTime(firstSchedule); if (SCHEDULE_FREQUENCY.DAILY == scheduleFreq) { cal.add(Calendar.HOUR, 24 * iterations); } else if (SCHEDULE_FREQUENCY.WEEKLY == scheduleFreq) { cal.add(Calendar.DATE, 7 * iterations); } else if (SCHEDULE_FREQUENCY.MONTHLY == scheduleFreq) { cal.add(Calendar.MONTH, 1 * iterations); } return cal.getTimeInMillis(); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static Calendar convertDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '1')) && ((val.charAt(5) >= '0') && (val.charAt(5) <= '9')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '3')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /*/* w w w.j a v a 2 s .co m*/ * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(4, 6)); int day = Integer.parseInt(val.substring(6, 8)); Calendar retval = new GregorianCalendar(getServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR, 0); retval.set(Calendar.MINUTE, 0); retval.set(Calendar.SECOND, 0); retval.getTimeInMillis(); // Force update calculations return (retval); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } }
From source file:ezbake.services.search.SSRServiceHandler.java
private Facet getDateRangeFacets(String field, String label) { GregorianCalendar calendar = new GregorianCalendar(); Facet dateFacet = new Facet(); RangeFacet dateRangeFacet = new RangeFacet(); BaseFacetValue dateField = new BaseFacetValue(); dateField.setFacetField(field);// w ww .j a va 2 s .c o m dateRangeFacet.setField(dateField); FacetRange last24 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last24hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last24.setRangeFrom(String.valueOf(last24hoursMS)); dateRangeFacet.addToRanges(last24); FacetRange last48 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last48hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last48.setRangeFrom(String.valueOf(last48hoursMS)); dateRangeFacet.addToRanges(last48); FacetRange last72 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last72hoursMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last72.setRangeFrom(String.valueOf(last72hoursMS)); dateRangeFacet.addToRanges(last72); FacetRange lastWeek = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -4); last7daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastWeek.setRangeFrom(String.valueOf(last7daysMS)); dateRangeFacet.addToRanges(lastWeek); FacetRange last30Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -23); last30daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last30Days.setRangeFrom(String.valueOf(last30daysMS)); dateRangeFacet.addToRanges(last30Days); FacetRange last90Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -60); last90daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last90Days.setRangeFrom(String.valueOf(last90daysMS)); dateRangeFacet.addToRanges(last90Days); FacetRange lastYear = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -275); last365daysMS = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastYear.setRangeFrom(String.valueOf(last365daysMS)); dateRangeFacet.addToRanges(lastYear); FacetRequest dateRequest = new FacetRequest(); dateRequest.setRangeFacet(dateRangeFacet); dateFacet.setLabel(label); dateFacet.setFacet(dateRequest); return dateFacet; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static Calendar convertTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format, \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':') && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':') && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /*/*from ww w .ja v a 2s.c om*/ * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int hour = Integer.parseInt(val.substring(0, 2)); int minute = Integer.parseInt(val.substring(3, 5)); int second = Integer.parseInt(val.substring(6, 8)); Calendar retval = new GregorianCalendar(getServerTimeZone()); retval.set(Calendar.YEAR, 1); retval.set(Calendar.MONTH, 0); retval.set(Calendar.DAY_OF_MONTH, 1); retval.set(Calendar.HOUR, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); retval.getTimeInMillis(); // Force update calculations return (retval); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format \"" + val + "\" is invalid"); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseSchema.java
public static Calendar convertDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '1')) && ((val.charAt(5) >= '0') && (val.charAt(5) <= '9')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '3')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /*/* w w w .j av a 2 s .c o m*/ * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(4, 6)); int day = Integer.parseInt(val.substring(6, 8)); Calendar retval = new GregorianCalendar(getServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR, 0); retval.set(Calendar.MINUTE, 0); retval.set(Calendar.SECOND, 0); retval.getTimeInMillis(); // Force update calculations return (retval); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } }