Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the year from a date code/*w w  w.  j a v  a 2 s  . c  om*/
 * @param strDate The date code
 * @return The Year
 */
public static int getYear(String strDate) {
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = null;
    try {
        date = format.parse(strDate);
    } catch (ParseException ex) {
        return -1;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return calendar.get(Calendar.YEAR);
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the month from a date code/*from w w  w  .  java2 s  . co  m*/
 * @param strDate The date code
 * @return The month index (0 - 11)
 */
public static int getMonth(String strDate) {
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = null;
    try {
        date = format.parse(strDate);
    } catch (ParseException ex) {
        return -1;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return calendar.get(Calendar.MONTH);
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the day of month from a date code
 * @param strDate The date code//from ww  w .java2  s  . c  o  m
 * @return The day
 */
public static int getDay(String strDate) {
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = null;
    try {
        date = format.parse(strDate);
    } catch (ParseException ex) {
        return -1;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Get the day of week of a given date using the pattern
 * {@link #DATE_PATTERN }/*from  ww w.  j  a  v  a 2s  .co  m*/
 * @param strDate The date to parse
 * @return The day of week of the given date, or -1 if the date could not be
 *         parsed
 */
public static int getDayOfWeek(String strDate) {
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = null;
    try {
        date = format.parse(strDate);
    } catch (ParseException ex) {
        return -1;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return calendar.get(Calendar.DAY_OF_WEEK);
}

From source file:org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount.java

private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception {

    // Create a container if it does not exist.
    container.createIfNotExists();//from   w  ww  .  ja v  a  2  s  .c  o  m

    // Create a new shared access policy.
    SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();

    // Create a UTC Gregorian calendar value.
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    // Specify the current time as the start time for the shared access
    // signature.
    //
    calendar.setTime(new Date());
    sasPolicy.setSharedAccessStartTime(calendar.getTime());

    // Use the start time delta one hour as the end time for the shared
    // access signature.
    calendar.add(Calendar.HOUR, 10);
    sasPolicy.setSharedAccessExpiryTime(calendar.getTime());

    if (readonly) {
        // Set READ permissions
        sasPolicy
                .setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST));
    } else {
        // Set READ and WRITE permissions.
        //
        sasPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
                SharedAccessBlobPermissions.LIST));
    }

    // Create the container permissions.
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

    // Turn public access to the container off.
    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF);

    container.uploadPermissions(containerPermissions);

    // Create a shared access signature for the container.
    String sas = container.generateSharedAccessSignature(sasPolicy, null);
    // HACK: when the just generated SAS is used straight away, we get an
    // authorization error intermittently. Sleeping for 1.5 seconds fixes that
    // on my box.
    Thread.sleep(1500);

    // Return to caller with the shared access signature.
    return sas;
}

From source file:org.getobjects.appserver.core.WOMessage.java

public static String httpFormatDate(final Date _date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(_date);
    return httpFormatDate(cal);
}

From source file:org.mule.module.netsuite.api.util.XmlGregorianCalendarFactory.java

public XMLGregorianCalendar toXmlCalendar(Date date) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    return dataTypeFactory.newXMLGregorianCalendar(calendar);
}

From source file:com.projity.server.data.MPXConverter.java

public static void toProjityOptions(ProjectHeader projectHeader, Context context) {

    CalendarOption calendarOption = CalendarOption.getInstance();
    calendarOption.setHoursPerDay(projectHeader.getMinutesPerDay().doubleValue() / 60.0D);
    calendarOption.setHoursPerWeek(projectHeader.getMinutesPerWeek().doubleValue() / 60.0D);

    calendarOption.setDaysPerMonth(projectHeader.getDaysPerMonth().doubleValue());

    Date d = projectHeader.getDefaultStartTime();
    if (d != null) {
        GregorianCalendar defaultStart = new GregorianCalendar();
        defaultStart.setTime(d);
        calendarOption.setDefaultStartTime(defaultStart);
    }//ww  w .ja  va 2  s .com
    Date e = projectHeader.getDefaultEndTime();
    if (e != null) {
        GregorianCalendar defaultEnd = new GregorianCalendar();
        defaultEnd.setTime(e);
        calendarOption.setDefaultEndTime(defaultEnd);
    }

}

From source file:com.fatminds.vaadin.cmis.property.CalendarPropertyConverter.java

@Override
public GregorianCalendar parse(Date value) throws ConversionException {
    if (value == null) {
        return null;
    }//from w  w w.java 2  s. c  o  m
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(value);
    return cal;
}

From source file:ru.schernolyas.websockettest.testproject.ws.command.LoginCommand.java

@Override
public Envelope execute(Envelope envelope) throws Exception {
    JSONParser parser = new JSONParser();
    JSONObject inData = (JSONObject) parser.parse(envelope.getData());
    String email = (String) inData.get("email");
    String password = (String) inData.get("password");
    JSONObject outData = new JSONObject();
    try {/*from   w  w  w .j av a 2 s .  co  m*/
        Token token = EJBUtil.getInstance().findUserService().loginUser(email, password);
        outData.put("api_token", token.getId());
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(token.getExpiration());
        String dateFormat = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toXMLFormat();
        outData.put("api_token_expiration_date", dateFormat);

    } catch (UserNotFoundException ue) {

        outData.put("error_description", "Customer not found");
        outData.put("error_code", "customer.notFound");
    }
    envelope.setData(outData.toJSONString());
    return envelope;
}