Example usage for java.util Calendar AM_PM

List of usage examples for java.util Calendar AM_PM

Introduction

In this page you can find the example usage for java.util Calendar AM_PM.

Prototype

int AM_PM

To view the source code for java.util Calendar AM_PM.

Click Source Link

Document

Field number for get and set indicating whether the HOUR is before or after noon.

Usage

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * ?Calender?Calender?  20090802080808 ?
 * //from ww w.  j  a va 2s. c  o m
 */
public static long getLongTime() {
    try {
        long longCalendar = 0;

        // ?
        Calendar cldCurrent = Calendar.getInstance();

        // 
        String strYear = String.valueOf(cldCurrent.get(Calendar.YEAR));
        String strMonth = String.valueOf(cldCurrent.get(Calendar.MONTH) + 1);
        String strDate = String.valueOf(cldCurrent.get(Calendar.DATE));
        String strHour = String.valueOf(cldCurrent.get(Calendar.HOUR));
        String strAM_PM = String.valueOf(cldCurrent.get(Calendar.AM_PM));
        String strMinute = String.valueOf(cldCurrent.get(Calendar.MINUTE));
        String strSecond = String.valueOf(cldCurrent.get(Calendar.SECOND));

        // ?24?
        // strAM_PM=="1",??strHour?12
        if (strAM_PM.equals("1")) {
            strHour = String.valueOf(Long.parseLong(strHour) + 12);
        }

        // ??
        if (strMonth.length() < 2) {
            strMonth = "0" + strMonth;
        }
        if (strDate.length() < 2) {
            strDate = "0" + strDate;
        }
        if (strHour.length() < 2) {
            strHour = "0" + strHour;
        }
        if (strMinute.length() < 2) {
            strMinute = "0" + strMinute;
        }
        if (strSecond.length() < 2) {
            strSecond = "0" + strSecond;
        }
        // ?
        longCalendar = Long.parseLong(strYear + strMonth + strDate + strHour + strMinute + strSecond);

        // ?
        return longCalendar;
    } catch (Exception Exp) {
        return 0;
    }
}

From source file:org.apereo.portal.portlets.portletadmin.PortletDefinitionForm.java

/**
 * Return the full date and time at which this portlet shoudl be automatically
 * published.  This value is built from the individual date/time fields.
 *
 * @return//from w  ww . jav  a  2 s.  c o m
 */
public Date getPublishDateTime() {
    if (this.getPublishDate() == null) {
        return null;
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(this.getPublishDate());
    cal.set(Calendar.HOUR, this.getPublishHour());
    cal.set(Calendar.MINUTE, this.getPublishMinute());
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.AM_PM, this.getPublishAmPm());
    return cal.getTime();
}

From source file:org.apereo.portal.portlets.portletadmin.PortletDefinitionForm.java

/**
 * Return the full date and time at which this portlet shoudl be automatically
 * expired.  This value is built from the individual date/time fields.
 *
 * @return//from  w  w  w.ja  va2  s.  co m
 */
public Date getExpirationDateTime() {
    if (this.getExpirationDate() == null) {
        return null;
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(this.getExpirationDate());
    cal.set(Calendar.HOUR, this.getExpirationHour());
    cal.set(Calendar.MINUTE, this.getExpirationMinute());
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.AM_PM, this.getExpirationAmPm());
    return cal.getTime();
}

From source file:org.sqlite.date.FastDateParser.java

/**
 * Obtain a Strategy given a field from a SimpleDateFormat pattern
 * @param formatField A sub-sequence of the SimpleDateFormat pattern
 * @param definingCalendar The calendar to obtain the short and long values
 * @return The Strategy that will handle parsing for the field
 *///from ww w.  j  av  a  2 s . c om
private Strategy getStrategy(final String formatField, final Calendar definingCalendar) {
    switch (formatField.charAt(0)) {
    case '\'':
        if (formatField.length() > 2) {
            return new CopyQuotedStrategy(formatField.substring(1, formatField.length() - 1));
        }
        //$FALL-THROUGH$
    default:
        return new CopyQuotedStrategy(formatField);
    case 'D':
        return DAY_OF_YEAR_STRATEGY;
    case 'E':
        return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar);
    case 'F':
        return DAY_OF_WEEK_IN_MONTH_STRATEGY;
    case 'G':
        return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
    case 'H': // Hour in day (0-23)
        return HOUR_OF_DAY_STRATEGY;
    case 'K': // Hour in am/pm (0-11) 
        return HOUR_STRATEGY;
    case 'M':
        return formatField.length() >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar)
                : NUMBER_MONTH_STRATEGY;
    case 'S':
        return MILLISECOND_STRATEGY;
    case 'W':
        return WEEK_OF_MONTH_STRATEGY;
    case 'a':
        return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar);
    case 'd':
        return DAY_OF_MONTH_STRATEGY;
    case 'h': // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
        return HOUR12_STRATEGY;
    case 'k': // Hour in day (1-24), i.e. midnight is 24, not 0
        return HOUR24_OF_DAY_STRATEGY;
    case 'm':
        return MINUTE_STRATEGY;
    case 's':
        return SECOND_STRATEGY;
    case 'w':
        return WEEK_OF_YEAR_STRATEGY;
    case 'y':
        return formatField.length() > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY;
    case 'X':
        return ISO8601TimeZoneStrategy.getStrategy(formatField.length());
    case 'Z':
        if (formatField.equals("ZZ")) {
            return ISO_8601_STRATEGY;
        }
        //$FALL-THROUGH$
    case 'z':
        return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar);
    }
}

From source file:com.application.utils.FastDateParser.java

/**
 * Obtain a Strategy given a field from a SimpleDateFormat pattern
 *
 * @param formatField      A sub-sequence of the SimpleDateFormat pattern
 * @param definingCalendar The calendar to obtain the short and long values
 * @return The Strategy that will handle parsing for the field
 *//*from w w w  .  j  av  a 2  s .c  om*/
private Strategy getStrategy(final String formatField, final Calendar definingCalendar) {
    switch (formatField.charAt(0)) {
    case '\'':
        if (formatField.length() > 2) {
            return new CopyQuotedStrategy(formatField.substring(1, formatField.length() - 1));
        }
        //$FALL-THROUGH$
    default:
        return new CopyQuotedStrategy(formatField);
    case 'D':
        return DAY_OF_YEAR_STRATEGY;
    case 'E':
        return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar);
    case 'F':
        return DAY_OF_WEEK_IN_MONTH_STRATEGY;
    case 'G':
        return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
    case 'H':
        return MODULO_HOUR_OF_DAY_STRATEGY;
    case 'K':
        return HOUR_STRATEGY;
    case 'M':
        return formatField.length() >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar)
                : NUMBER_MONTH_STRATEGY;
    case 'S':
        return MILLISECOND_STRATEGY;
    case 'W':
        return WEEK_OF_MONTH_STRATEGY;
    case 'a':
        return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar);
    case 'd':
        return DAY_OF_MONTH_STRATEGY;
    case 'h':
        return MODULO_HOUR_STRATEGY;
    case 'k':
        return HOUR_OF_DAY_STRATEGY;
    case 'm':
        return MINUTE_STRATEGY;
    case 's':
        return SECOND_STRATEGY;
    case 'w':
        return WEEK_OF_YEAR_STRATEGY;
    case 'y':
        return formatField.length() > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY;
    case 'Z':
    case 'z':
        return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar);
    }
}

From source file:DateUtil.java

/**
 * Some external entities still use Calendar.* fields to do some of their own
 * date calculations, so this provides a mapping from DateUtil.*_MS to the
 * closest Calendar.* field. Note that if the milliseconds is not one of the
 * DateUtil constants, the smallest known field will be returned.
 * /*from  w ww .j a v a  2s  . c om*/
 * @param millis
 *          The DateUtil.*_MS field to map from.
 * @return The int representing the closest Calendar.* field.
 */
public static int mapLongToCal(long millis) {
    if (millis == YEAR_MS)
        return Calendar.YEAR;
    else if (millis == QUARTER_MS)
        return Calendar.MONTH; // There is no Calendar.QUARTER, return MONTH
    else if (millis == MONTH_MS)
        return Calendar.MONTH;
    else if (millis == WEEK_MS)
        return Calendar.WEEK_OF_YEAR;
    else if (millis == DAY_MS)
        return Calendar.DAY_OF_MONTH;
    else if (millis == AMPM_MS)
        return Calendar.AM_PM;
    else if (millis == HOUR_MS)
        return Calendar.HOUR_OF_DAY;
    return Calendar.MINUTE;
}

From source file:com.owncloud.android.ui.fragment.contactsbackup.ContactsBackupFragment.java

@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
    selectedDate = new Date(year, month, dayOfMonth);

    String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
            + OCFile.PATH_SEPARATOR;/*from ww w. j  a  v  a  2 s. c o m*/
    OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderString);
    Vector<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder,
            false);

    // find file with modification with date and time between 00:00 and 23:59
    // if more than one file exists, take oldest
    Calendar date = Calendar.getInstance();
    date.set(year, month, dayOfMonth);

    // start
    date.set(Calendar.HOUR, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 1);
    date.set(Calendar.MILLISECOND, 0);
    date.set(Calendar.AM_PM, Calendar.AM);
    Long start = date.getTimeInMillis();

    // end
    date.set(Calendar.HOUR, 23);
    date.set(Calendar.MINUTE, 59);
    date.set(Calendar.SECOND, 59);
    Long end = date.getTimeInMillis();

    OCFile backupToRestore = null;

    for (OCFile file : backupFiles) {
        if (start < file.getModificationTimestamp() && end > file.getModificationTimestamp()) {
            if (backupToRestore == null) {
                backupToRestore = file;
            } else if (backupToRestore.getModificationTimestamp() < file.getModificationTimestamp()) {
                backupToRestore = file;
            }
        }
    }

    if (backupToRestore != null) {
        Fragment contactListFragment = ContactListFragment.newInstance(backupToRestore,
                contactsPreferenceActivity.getAccount());

        contactsPreferenceActivity.getSupportFragmentManager().beginTransaction()
                .replace(R.id.frame_container, contactListFragment, ContactListFragment.TAG)
                .addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST).commit();
    } else {
        Toast.makeText(contactsPreferenceActivity, R.string.contacts_preferences_no_file_found,
                Toast.LENGTH_SHORT).show();
    }
}

From source file:org.apereo.portal.portlets.portletadmin.PortletDefinitionForm.java

public void setPublishDateTime(Date publish) {
    if (publish != null) {
        this.setPublishDate(publish);
        Calendar cal = Calendar.getInstance();
        cal.setTime(publish);/*  w w w.  j  a v a2  s  .c o m*/
        if (cal.get(Calendar.HOUR) == 0) {
            this.setPublishHour(12);
        } else {
            this.setPublishHour(cal.get(Calendar.HOUR));
        }
        this.setPublishMinute(cal.get(Calendar.MINUTE));
        this.setPublishAmPm(cal.get(Calendar.AM_PM));
    }
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParser.java

/**
 * Obtain a Strategy given a field from a SimpleDateFormat pattern
 * @param formatField A sub-sequence of the SimpleDateFormat pattern
 * @param definingCalendar The calendar to obtain the short and long values
 * @return The Strategy that will handle parsing for the field
 *//*from  w ww.j a v  a 2s .  c om*/
private Strategy getStrategy(final char f, final int width, final Calendar definingCalendar) {
    switch (f) {
    default:
        throw new IllegalArgumentException("Format '" + f + "' not supported");
    case 'D':
        return DAY_OF_YEAR_STRATEGY;
    case 'E':
        return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar);
    case 'F':
        return DAY_OF_WEEK_IN_MONTH_STRATEGY;
    case 'G':
        return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
    case 'H': // Hour in day (0-23)
        return HOUR_OF_DAY_STRATEGY;
    case 'K': // Hour in am/pm (0-11) 
        return HOUR_STRATEGY;
    case 'M':
        return width >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar) : NUMBER_MONTH_STRATEGY;
    case 'S':
        return MILLISECOND_STRATEGY;
    case 'W':
        return WEEK_OF_MONTH_STRATEGY;
    case 'a':
        return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar);
    case 'd':
        return DAY_OF_MONTH_STRATEGY;
    case 'h': // Hour in am/pm (1-12), i.e. midday/midnight is 12, not 0
        return HOUR12_STRATEGY;
    case 'k': // Hour in day (1-24), i.e. midnight is 24, not 0
        return HOUR24_OF_DAY_STRATEGY;
    case 'm':
        return MINUTE_STRATEGY;
    case 's':
        return SECOND_STRATEGY;
    case 'u':
        return DAY_OF_WEEK_STRATEGY;
    case 'w':
        return WEEK_OF_YEAR_STRATEGY;
    case 'y':
    case 'Y':
        return width > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY;
    case 'X':
        return ISO8601TimeZoneStrategy.getStrategy(width);
    case 'Z':
        if (width == 2) {
            return ISO8601TimeZoneStrategy.ISO_8601_3_STRATEGY;
        }
        //$FALL-THROUGH$
    case 'z':
        return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar);
    }
}

From source file:com.appeligo.alerts.KeywordAlertChecker.java

/**
 * @param timeZone the user's timezone/* w  ww .java  2 s  . c o  m*/
 * @param startOfDay We're using the value of earliestSmsTime (user account setting) as a starting point,
 * so anything before this time is credited to the previous day)
 * @return 12am (midnight) using system time (not user time) because "Date" objects stored in SQL
 * come back in system time.
 */
private Date calculateDay(TimeZone timeZone, Time startOfDay) {
    Calendar cal = Calendar.getInstance(timeZone);
    Calendar start = Calendar.getInstance();
    start.setTimeInMillis(startOfDay.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 0 - start.get(Calendar.HOUR_OF_DAY));
    cal.add(Calendar.MINUTE, 0 - start.get(Calendar.MINUTE));
    cal.add(Calendar.SECOND, 0 - start.get(Calendar.SECOND));
    cal.clear(Calendar.MILLISECOND);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.HOUR_OF_DAY);
    cal.clear(Calendar.HOUR);
    cal.clear(Calendar.AM_PM);
    TimeZone systemTimeZone = TimeZone.getDefault();
    long now = System.currentTimeMillis();
    long difference = systemTimeZone.getOffset(now) - timeZone.getOffset(now);
    return new Date(cal.getTimeInMillis() - difference);
}