Example usage for java.util GregorianCalendar get

List of usage examples for java.util GregorianCalendar get

Introduction

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

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:com.google.code.rptm.mailarchive.YearMonth.java

/**
 * Construct a new instance with the year and month given by the current data.
 *//*from www .jav a2  s.  co m*/
public YearMonth() {
    GregorianCalendar cal = new GregorianCalendar();
    year = cal.get(Calendar.YEAR);
    month = cal.get(Calendar.MONTH) + 1;
}

From source file:de.sindzinski.wetter.util.Utility.java

@SuppressLint("StringFormatMatches")
public static String getHourlyDayString(Context context, long timeInMillis, String timeZoneId) {
    // The day string for forecast uses the following logic:
    // For today: "Today, June 8"
    // For tomorrow:  "Tomorrow"
    // For the next 5 days: "Wednesday
    // " (just the day name)
    // For all days after that: "Mon Jun 8"
    TimeZone timeZone;//  w  w  w  . j  a  v a  2  s  .co m
    if (timeZoneId.equals("")) {
        timeZone = TimeZone.getDefault();
    } else {
        timeZone = TimeZone.getTimeZone(timeZoneId);
    }
    GregorianCalendar gregorianCalendar = new GregorianCalendar(timeZone);
    gregorianCalendar.setTimeInMillis(timeInMillis);
    int day = gregorianCalendar.get(Calendar.DAY_OF_MONTH);
    //code for formatting the date
    Calendar calendar = Calendar.getInstance();
    int today = calendar.get(Calendar.DAY_OF_MONTH);
    Date time = gregorianCalendar.getTime();

    //        SimpleDateFormat shortDateFormat = new SimpleDateFormat("EEE MMM dd HH:MM");
    //        shortDateFormat.setTimeZone(timeZone);

    try {
        if (day < today + 1) {
            // If the input date is less than a week in the future, just return the day name.

            SimpleDateFormat shortDateFormat = new SimpleDateFormat("HH:00");
            shortDateFormat.setTimeZone(timeZone);
            String dsorig = shortDateFormat.format(timeInMillis);
            Date dconv = shortDateFormat.parse(dsorig);
            String sconv = shortDateFormat.format(dconv);
            return sconv;

        } else {
            // Otherwise, use the form "Mon Jun 3"
            SimpleDateFormat shortDateFormat = new SimpleDateFormat("EEE HH:00");
            shortDateFormat.setTimeZone(timeZone);
            String dsorig = shortDateFormat.format(timeInMillis);
            Date dconv = shortDateFormat.parse(dsorig);
            String sconv = shortDateFormat.format(dconv);
            return sconv;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
}

From source file:org.squale.squalecommon.enterpriselayer.facade.component.AuditFacade.java

/**
 * Permet de reprogramm un audit sur une application au lendemain. si il s'agit d'un audit de suivi, l'audit dj
 * programm est supprim/*from w  w  w  .ja  v a  2  s.  c  o  m*/
 * 
 * @param pAudit AuditDTO dfinissant l'id de l'audit
 * @return l'audit reprogramm
 * @throws JrafEnterpriseException si erreur
 */
public static AuditDTO restartAudit(AuditDTO pAudit) throws JrafEnterpriseException {
    AuditDTO auditDTO = null;
    ISession session = null;
    try {
        // cration d'une session Hibernate
        session = PERSISTENTPROVIDER.getSession();
        AuditDAOImpl auditDAO = AuditDAOImpl.getInstance();
        // On rcupre l'audit dont l'id est renseign par pAudit
        AuditBO failedAudit = (AuditBO) auditDAO.load(session, new Long(pAudit.getID()));
        // On transforme le bo en dto
        auditDTO = AuditTransform.bo2Dto(failedAudit, pAudit.getApplicationId());
        // On change la date pour le lancer le lendemain  0:00
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(GregorianCalendar.HOUR_OF_DAY,
                ApplicationFacade.HOUR_OF_AUDIT - cal.get(GregorianCalendar.HOUR_OF_DAY));
        cal.add(GregorianCalendar.MINUTE,
                ApplicationFacade.MINUTE_OF_AUDIT - cal.get(GregorianCalendar.MINUTE));
        auditDTO.setDate(cal.getTime());
        // Son status sera en attente d'excution
        auditDTO.setStatus(AuditBO.NOT_ATTEMPTED);
        // On insre l'audit avec un traitement diffrent selon le type de l'audit
        if (auditDTO.getType().equals(AuditBO.MILESTONE)) {
            auditDTO = insertAudit(auditDTO);
        } else { // Il s'agit d'un audit de suivi
            auditDTO = restartNormalAudit(auditDTO);
        }
    } catch (JrafDaoException e) {
        FacadeHelper.convertException(e, AuditFacade.class.getName() + ".restartAudit");
    } finally {
        FacadeHelper.closeSession(session, AuditFacade.class.getName() + ".restartAudit");
    }
    return auditDTO;
}

From source file:MyServlet.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    GregorianCalendar calendar = new GregorianCalendar();
    Date date1 = new Date();
    calendar.setTime(date1);/* w  ww .ja va2s.co m*/
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    if (hour < 9 || hour > 17) {
        chain.doFilter(request, response);
    } else {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD>");
        out.println("<TITLE>");
        out.println("Get Back to Work!");
        out.println("</TITLE>");
        out.println("</HEAD>");
        out.println("<BODY>");
        out.println("<H1>Get Back to Work!</H1>");
        out.println("Sorry, that resource is not available now.");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}

From source file:Calendar.java

public void setMonth(int year, int month) {
    for (int i = 1; i < 7; ++i)
        for (int j = 0; j < 7; ++j)
            calendar[i][j] = " ";
    java.util.GregorianCalendar cal = new java.util.GregorianCalendar();
    cal.set(year, month, 1);/*from   w  ww .j a  v  a2 s .  c  o m*/
    int offset = cal.get(java.util.GregorianCalendar.DAY_OF_WEEK) - 1;
    offset += 7;
    int num = daysInMonth(year, month);
    for (int i = 0; i < num; ++i) {
        calendar[offset / 7][offset % 7] = Integer.toString(i + 1);
        ++offset;
    }
}

From source file:RandomFileTest.java

/**
   Writes employee data to a data output
   @param out the data output//w ww.  j a v a  2  s. c  o  m
*/
public void writeData(DataOutput out) throws IOException {
    DataIO.writeFixedString(name, NAME_SIZE, out);
    out.writeDouble(salary);

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(hireDay);
    out.writeInt(calendar.get(Calendar.YEAR));
    out.writeInt(calendar.get(Calendar.MONTH) + 1);
    out.writeInt(calendar.get(Calendar.DAY_OF_MONTH));
}

From source file:TextFileTest.java

/**
 * Writes employee data to a print writer
 * @param out the print writer/*from   w w  w  .j a v a  2  s .c  o m*/
 */
public void writeData(PrintWriter out) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(hireDay);
    out.println(name + "|" + salary + "|" + calendar.get(Calendar.YEAR) + "|"
            + (calendar.get(Calendar.MONTH) + 1) + "|" + calendar.get(Calendar.DAY_OF_MONTH));
}

From source file:org.mule.transport.http.HttpResponseTestCase.java

private void validateDate(Date date) {
    GregorianCalendar cookieDate = new GregorianCalendar();
    cookieDate.setTime(date);//  w ww .  j a  v  a 2s  . c om

    assertEquals(2014, cookieDate.get(GregorianCalendar.YEAR));
    assertEquals(12, cookieDate.get(GregorianCalendar.DAY_OF_MONTH));
    assertEquals(11, cookieDate.get(GregorianCalendar.MONTH));
}

From source file:org.jbpm.formModeler.core.processing.formProcessing.Functions.java

public Map getValidDays(String sMonth, String sYear) {

    int month = Integer.decode(sMonth).intValue();
    int year = Integer.decode(sYear).intValue();
    GregorianCalendar gc = new GregorianCalendar(year, month, 1);

    Map days = new HashMap();

    while (gc.get(GregorianCalendar.MONTH) == month) {
        Integer value = new Integer(gc.get(GregorianCalendar.DAY_OF_MONTH));
        days.put(value, value.toString());
        gc.set(GregorianCalendar.DAY_OF_MONTH, value.intValue() + 1);
    }/*w  w  w.  jav  a2 s .  c  o m*/

    return days;
}

From source file:ca.mudar.parkcatcher.ui.fragments.FavoritesFragment.java

private String[] getSelectionArgs() {

    final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar();

    final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7
            : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1);
    final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY)
            + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d;
    final double hourOfWeek = parkingHour + (dayOfWeek - 1) * 24;

    // API uses values 0-365 (or 364)
    final int dayOfYear = parkingCalendar.get(Calendar.DAY_OF_YEAR) - 1;

    final int duration = parkingApp.getParkingDuration();

    return new String[] { Double.toString(hourOfWeek), Integer.toString(duration),
            Integer.toString(dayOfYear) };
}