Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:msec.org.Tools.java

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }//  ww  w. j a  v  a2  s .co  m
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }

    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:com.camel.framework.utils.DateUtils.java

/**
 * //from ww  w . j  a  v  a  2 s. c om
 * 
 * @param objGC Calender
 * @param strType ?"yyyy-MM-dd HH:mm:ss"
 * @return strType?
 */
public static String getDateString(GregorianCalendar objGC, String strType) {
    if (objGC == null) {
        return "";
    }
    Date objDate = objGC.getTime();
    return getDateString(objDate, strType);
}

From source file:org.eclipse.ecr.platform.query.nxql.NXQLQueryBuilder.java

public static String getStringValue(DocumentModel model, PredicateFieldDefinition fieldDescriptor)
        throws ClientException {
    Object rawValue = getRawValue(model, fieldDescriptor);
    if (rawValue == null) {
        return null;
    }/*from   w  w w .j  a  v  a  2 s.c  om*/
    String value;
    if (rawValue instanceof GregorianCalendar) {
        GregorianCalendar gc = (GregorianCalendar) rawValue;
        value = "TIMESTAMP '" + getDateFormat().format(gc.getTime()) + "'";
    } else if (rawValue instanceof Date) {
        Date date = (Date) rawValue;
        value = "TIMESTAMP '" + getDateFormat().format(date) + "'";
    } else if (rawValue instanceof Integer || rawValue instanceof Long || rawValue instanceof Double) {
        value = rawValue.toString(); // no quotes
    } else if (rawValue instanceof Boolean) {
        value = ((Boolean) rawValue).booleanValue() ? "1" : "0";
    } else {
        value = rawValue.toString().trim();
        if (value.equals("")) {
            return null;
        }
        String fieldType = getFieldType(model, fieldDescriptor);
        if ("long".equals(fieldType) || "integer".equals(fieldType) || "double".equals(fieldType)) {
            return value;
        } else {
            return prepareStringLiteral(value, true, true);
        }
    }
    return value;
}

From source file:com.apextom.util.DateUtil.java

/**
 * //w  w  w. j av  a2s.  c  o  m
 *
 * @return
 */
public static String getFirstDay(boolean isNeedHH24MISS) {
    SimpleDateFormat df = new SimpleDateFormat(YYYY_MM_DD);
    Calendar calendar = Calendar.getInstance();
    Date theDate = calendar.getTime();
    GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
    gcLast.setTime(theDate);
    gcLast.set(Calendar.DAY_OF_MONTH, 1);
    String day_first = df.format(gcLast.getTime());
    StringBuffer str = new StringBuffer().append(day_first);
    if (isNeedHH24MISS) {
        str.append(" 00:00:00");
    }
    return str.toString();
}

From source file:org.mifos.calendar.CalendarUtils.java

/**
 * Set the day of week according to given start day to the require weekday, i.e. so it matches the meeting week day.
 *
 * e.g. - If start date is Monday 9 June 2008 and meeting week day is Tuesday, then roll forward the date to Tuesday
 * 10 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is Saturday, then roll forward the
 * date to Saturday 14 June 2008 - or if start date is Tuesday 10 2008 June and meeting week day is Monday, then
 * roll forward the date to Monday 16 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is
 * Sunday, then keep the date as Sunday 8 June 2008 - or if start date is Saturday 7 June 2008 and meeting week day
 * is Sunday, then roll forward the date to Sunday 9 June 2008.
 *///from  w w w  .ja  va2 s  . co  m
public static DateTime getFirstDateForWeek(final DateTime startDate, final int dayOfWeek) {

    /*
     * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class
     */
    int calendarDayOfWeek = (dayOfWeek % 7) + 1;

    final GregorianCalendar firstDateForWeek = new GregorianCalendar();
    firstDateForWeek.setTime(startDate.toDate());

    int startDateWeekDay = firstDateForWeek.get(Calendar.DAY_OF_WEEK);
    int amountOfDaysToAdd = calendarDayOfWeek - startDateWeekDay;
    if (amountOfDaysToAdd < 0) {
        amountOfDaysToAdd += 7;
    }
    firstDateForWeek.add(Calendar.DAY_OF_WEEK, amountOfDaysToAdd);
    return new DateTime(firstDateForWeek.getTime());
}

From source file:io.uengine.util.DateUtils.java

public static long getDiffHours(String startStr, String endStr) {
    GregorianCalendar start = getGregorianCalendar(startStr);
    GregorianCalendar end = getGregorianCalendar(endStr);
    return (start.getTime().getTime() - end.getTime().getTime()) / (60 * 1000);
}

From source file:io.uengine.util.DateUtils.java

/**
 * ? ?  . ?  ? ? ./*  ww w  .j  a v a 2  s. c  o  m*/
 * <p>
 * <pre>
 * long date = DateUtils.getDiffDays("20080501",DateUtils.getCurrentYyyymmdd())
 * </pre>
 * </p>
 *
 * @param startStr  
 * @param endStr   ?? 
 * @return ?
 */
public static long getDiffDays(String startStr, String endStr) {
    GregorianCalendar start = getGregorianCalendar(startStr);
    GregorianCalendar end = getGregorianCalendar(endStr);
    return (start.getTime().getTime() - end.getTime().getTime()) / 86400000;
}

From source file:org.webical.ical.RecurrenceUtil.java

public static java.util.Date getLastOccurrenceDate(Event event) throws WebicalException {
    if (!(event != null && isRecurrent(event))) {
        throw new WebicalException("This event is not recurrent: " + event);
    }// ww w .j  av a  2s  .  c  o  m

    Recurrence recurrence = getRecurrenceFromRecurrenceRuleSet(event.getrRule());
    if (recurrence != null) { // Check if the recurrence end date is set. Use this as last date value
        if (recurrence.getEndDay() != null) {
            return recurrence.getEndDay();
        }

        // Check for use of count to determine the end date
        if (recurrence.getCount() >= 1 && recurrence.getInterval() >= 1) {
            GregorianCalendar endDateCalendar = new GregorianCalendar();
            endDateCalendar.setTime(event.getDtStart());
            int amountToAdd = (recurrence.getCount() * recurrence.getInterval());
            endDateCalendar.add(getCalendarIdentifierForFrequency(recurrence.getFrequency()), amountToAdd);

            return endDateCalendar.getTime();
        }
    }
    return null;
}

From source file:org.mifos.calendar.CalendarUtils.java

public static DateTime getNextDayForMonthUsingWeekRankAndWeekday(final DateTime startDate,
        final int weekOfMonth, final int dayOfWeek, final int every) {

    /*/*from w ww  .  ja v a 2 s.  c  om*/
     * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class
     */
    int calendarDayOfWeek = (dayOfWeek % 7) + 1;

    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(startDate.toDate());

    DateTime scheduleDate;

    if (!RankOfDay.getRankOfDay(weekOfMonth).equals(RankOfDay.LAST)) {
        // apply month recurrence
        gc.add(GregorianCalendar.MONTH, every);
        gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek);
        gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, weekOfMonth);
        scheduleDate = new DateTime(gc.getTime().getTime());
    } else {// weekCount=-1
        gc.set(GregorianCalendar.DATE, 15);
        gc.add(GregorianCalendar.MONTH, every);
        gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek);
        int M1 = gc.get(GregorianCalendar.MONTH);
        // assumption: there are 5 weekdays in the month
        gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 5);
        int M2 = gc.get(GregorianCalendar.MONTH);
        // if assumption fails, it means there exists 4 weekdays in a
        // month, return last weekday date
        // if M1==M2, means there exists 5 weekdays otherwise 4 weekdays
        // in a month
        if (M1 != M2) {
            gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1);
            gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 4);
        }
        scheduleDate = new DateTime(gc.getTime().getTime());
    }

    return scheduleDate;
}

From source file:org.webical.ical.RecurrenceUtil.java

public static java.util.Date getNextOccurrenceDate(Event event, java.util.Date occurrenceDate)
        throws WebicalException, ParseException {
    if (!(event != null && isRecurrent(event))) {
        throw new WebicalException("This event is not recurrent: " + event);
    }// w w w .  j a  v  a 2 s .  c o m

    Recurrence recurrence = getRecurrenceFromRecurrenceRuleSet(event.getrRule());
    if (recurrence != null) { // Check for use of count to determine the end date
        if (recurrence.getCount() > 0 && recurrence.getInterval() > 0) {
            GregorianCalendar endDateCalendar = new GregorianCalendar();

            endDateCalendar.setTime(event.getDtStart());
            int amountToAdd = (recurrence.getCount() * recurrence.getInterval());
            endDateCalendar.add(getCalendarIdentifierForFrequency(recurrence.getFrequency()), amountToAdd);

            if (isApplicableOnDate(event, endDateCalendar.getTime())) {
                return endDateCalendar.getTime();
            }
            return null;
        }
    }
    return null;
}