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:Main.java

/**
 * Reset the time of a date/*from   ww w.  j  a  v a  2s  .c o m*/
 * @param date the date with time to reset
 * @return the 0 time date.
 */
public static Date zeroTimeDate(Date date) {
    final GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    gregorianCalendar.set(Calendar.HOUR_OF_DAY, 0);
    gregorianCalendar.set(Calendar.MINUTE, 0);
    gregorianCalendar.set(Calendar.SECOND, 0);
    gregorianCalendar.set(Calendar.MILLISECOND, 0);
    return gregorianCalendar.getTime();
}

From source file:org.toobsframework.biz.validation.CustomValidationUtils.java

/**
 * Given three integer inputs representing a date, checks to 
 * see if the specified date is after today's date.
 * @param day - int 1-31/*from w  ww.java  2 s. c o  m*/
 * @param month - int 1-12
 * @param year
 * @return
 */
public static boolean rejectIfDayMonthYearBeforeToday(Integer day, Integer month, Integer year) {
    if (day != null && month != null && year != null) {
        //construct Calendar object
        //set time fields with inputted parameters
        GregorianCalendar cal = new GregorianCalendar();
        // note month conversion: Calendar expects 0 based month param
        cal.set(year, month - 1, day);
        //get a date object out of the 
        Date closingDate = cal.getTime();

        //if the closing date is before right now,
        //then throw a validation error
        if (closingDate.before(new Date(System.currentTimeMillis()))) {
            return false;
        }
    }

    return true;
}

From source file:com.autentia.common.util.DateFormater.java

public static Date normalizeInitDate(Date date) {

    GregorianCalendar gCalendar = new GregorianCalendar();
    gCalendar.setTime(date);/*w  ww .j  a v a 2s  .co  m*/
    gCalendar.set(Calendar.HOUR_OF_DAY, 0);
    gCalendar.set(Calendar.MINUTE, 0);
    gCalendar.set(Calendar.SECOND, 0);
    gCalendar.set(Calendar.MILLISECOND, 0);

    return gCalendar.getTime();
}

From source file:org.onosproject.drivers.bti.Bti7000SnmpAlarmConsumer.java

/**
 * Converts an SNMP string representation into a {@link Date} object,
 * and applies time zone conversion to provide the time on the local machine, ie PSM server.
 *
 * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain
 *                            a timezone offset in 3 extra bytes
 * @param sysInfoTimeZone     Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
 * @param swVersion           Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
 * @return adjusted {@link Date} or a simple conversion if other fields are null.
 *//*from   w ww  .j a  v a  2  s.c  o m*/
public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone, String swVersion) {
    if (StringUtils.isBlank(actAlarmDateAndTime)) {
        return null;
    }

    GregorianCalendar decodedDateAndTimeCal = btiMakeCalendar(OctetString.fromHexString(actAlarmDateAndTime));
    if ((sysInfoTimeZone == null) || (swVersion == null)) {
        return decodedDateAndTimeCal.getTime();
    }

    TimeZone javaTimeZone = getTimeZone();
    decodedDateAndTimeCal.setTimeZone(javaTimeZone);

    GregorianCalendar localTime = new GregorianCalendar();
    localTime.setTimeInMillis(decodedDateAndTimeCal.getTimeInMillis());

    return localTime.getTime();
}

From source file:com.autentia.common.util.DateFormater.java

public static Date normalizeEndDate(Date date) {

    GregorianCalendar gCalendar = new GregorianCalendar();
    gCalendar.setTime(date);/*from w  ww .j  av  a  2s  .  c  o m*/
    gCalendar.set(Calendar.HOUR_OF_DAY, 23);
    gCalendar.set(Calendar.MINUTE, 59);
    gCalendar.set(Calendar.SECOND, 59);
    gCalendar.set(Calendar.MILLISECOND, 999);

    return gCalendar.getTime();
}

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

public static DateTime getNextDateForDay(final DateTime startDate, final int every) {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(startDate.toDate());/*from   w w  w .j av  a2 s  .  c  o  m*/

    gc.add(Calendar.DAY_OF_WEEK, every);
    return new DateTime(gc.getTime().getTime());
}

From source file:org.glite.slcs.caclient.impl.CMPRequest.java

private static CertTemplate makeCertTemplate(CertificateRequest certRequest, String issuerDN) {
    PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest(certRequest.getDEREncoded());
    CertificationRequestInfo pkcs10info = pkcs10.getCertificationRequestInfo();

    log.debug("Constructing CMP CertTemplate...");
    CertTemplate certTemplate = new CertTemplate();
    certTemplate.setPublicKey(pkcs10info.getSubjectPublicKeyInfo());
    certTemplate.setSubject(pkcs10info.getSubject());
    certTemplate.setIssuer(new X509Name(issuerDN));

    // validity//from  w  ww  .  j  a  v a 2  s. co  m
    OptionalValidity validity = new OptionalValidity();
    GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    // five minutes extra to before/after
    date.add(Calendar.MINUTE, -5);
    Time notBefore = new Time(date.getTime());
    date.add(Calendar.MINUTE, 5);
    // TODO: lifetime fixed to 1 mio seconds, should be possible to configure by user
    date.add(Calendar.SECOND, 1000000);
    Time notAfter = new Time(date.getTime());
    validity.setNotBefore(notBefore);
    validity.setNotAfter(notAfter);
    certTemplate.setValidity(validity);

    log.debug("Constructed " + certTemplate.toString());

    return certTemplate;
}

From source file:DateUtils.java

public static final String formatDate(Date dt, String format) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(dt);//from  w  w  w .  ja  v a  2  s.com

    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
    sdf.setTimeZone(TimeZone.getDefault());
    return (sdf.format(cal.getTime()));
}

From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java

private static JFreeChart buildChartForDive(StatQueryObject sqo) {
    Collection<StatSerie> s = sqo.getValues();
    String legend = I18nResourceManager.sharedInstance().getString("dive.times");
    TimeSeriesCollection collection = new TimeSeriesCollection();
    for (StatSerie statSerie : s) {
        TimeSeries ts = new TimeSeries(legend);
        for (StatPoint point : statSerie.getPoints()) {
            Date dd = (Date) point.getX();
            FixedMillisecond day = new FixedMillisecond(dd);
            Object index = ts.getDataItem(day);
            if (null != index) {
                GregorianCalendar gc = new GregorianCalendar();
                gc.setTime(dd);/*w w w .ja va2 s  .com*/
                gc.add(Calendar.MILLISECOND, 1);
                day = new FixedMillisecond(gc.getTime());
            }

            if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DEPTHS)) {
                ts.add(day, UnitsAgent.getInstance().convertLengthFromModel((Double) point.getY()));
            } else if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.TEMPERATURES)) {
                ts.add(day, UnitsAgent.getInstance().convertTemperatureFromModel((Double) point.getY()));
            } else {
                ts.add(day, point.getY());
            }
        }
        collection.addSeries(ts);
    }

    JFreeChart chart = createLineChart(collection, getXLabel(sqo), getYLabel(sqo));

    if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DIVE_TIME)) {
        XYPlot xyp = (XYPlot) chart.getPlot();
        ((NumberAxis) xyp.getRangeAxis()).setNumberFormatOverride(new HoursMinutesNumberFormat());
    }

    return chart;
}

From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java

/**
 * Load book from JSON file./*from  w  w w  .ja  v a 2s.  c o m*/
 * 
 * @return
 */
public static Book loadBook(File file) throws Exception {
    Book book = new Book();
    if (!file.exists()) {
        book.setName("Book");
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(new Date());
        cal.set(Calendar.DAY_OF_MONTH, 1);
        // create period
        Period newPeriod = new Period(cal.getTime());
        newPeriod.setId(Formatter.formatDateId(cal.getTime()));
        book.getPeriodList().add(newPeriod);
        book.setCurrPeriod(newPeriod);
        book.getAssetList().setName(App.getGuiProp("default.assets"));
        book.getLiabilityList().setName(App.getGuiProp("default.liability"));
        book.getExpenseList().setName(App.getGuiProp("default.expenses"));
        book.getIncomeList().setName(App.getGuiProp("default.income"));
        return book;
    }
    FileReader fr = null;
    try {
        fr = new FileReader(file);
        JSONTokener jsonTokener = new JSONTokener(fr);
        JSONObject root = new JSONObject(jsonTokener);
        JSONObject jsonBook = root.getJSONObject("book");
        book.setName(jsonBook.getString("name"));
        book.setCurrPeriodId(jsonBook.getString("currPeriodId"));
        parseAccounts(jsonBook.getJSONObject("assets"), book.getAssetList());
        parseAccounts(jsonBook.getJSONObject("liability"), book.getLiabilityList());
        parseAccounts(jsonBook.getJSONObject("income"), book.getIncomeList());
        parseAccounts(jsonBook.getJSONObject("expenses"), book.getExpenseList());
        parsePeriods(jsonBook.getJSONArray("periodList"), book.getPeriodList(), book);
    } finally {
        if (fr != null) {
            fr.close();
        }
    }
    return book;
}