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:phenoviewer.ReNameJFrame.java

private String replaceTokens(Date date, int counter, String path) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);/* w  w w  .  j  ava2  s. c  o m*/

    Map<String, Object> tokens = new HashMap<String, Object>();
    tokens.put("ERA", getText(gc.get(Calendar.ERA), "BC", "AD"));
    tokens.put("YEAR", getString(gc.get(Calendar.YEAR), 4, "0"));
    tokens.put("MONTH", getString(gc.get(Calendar.MONTH) + 1, 2, "0"));
    tokens.put("WEEK_OF_YEAR", getString(gc.get(Calendar.WEEK_OF_YEAR), 2, "0"));
    tokens.put("WEEK_OF_MONTH", getString(gc.get(Calendar.WEEK_OF_MONTH), 0, ""));
    tokens.put("DATE", getString(gc.get(Calendar.DATE), 2, "0"));
    tokens.put("DAY_OF_MONTH", getString(gc.get(Calendar.DAY_OF_MONTH), 2, "0"));
    tokens.put("DAY_OF_YEAR", getString(gc.get(Calendar.DAY_OF_YEAR), 3, "0"));
    tokens.put("DAY_OF_WEEK", getString(gc.get(Calendar.DAY_OF_WEEK), 0, ""));
    tokens.put("DAY_OF_WEEK_IN_MONTH", getString(gc.get(Calendar.DAY_OF_WEEK_IN_MONTH), 0, ""));
    tokens.put("AM_PM", getText(gc.get(Calendar.AM_PM), "AM", "PM"));
    tokens.put("HOUR", getString(gc.get(Calendar.HOUR), 2, "0"));
    tokens.put("HOUR_OF_DAY", getString(gc.get(Calendar.HOUR_OF_DAY), 2, "0"));
    tokens.put("MINUTE", getString(gc.get(Calendar.MINUTE), 2, "0"));
    tokens.put("SECOND", getString(gc.get(Calendar.SECOND), 2, "0"));
    tokens.put("MILLISECOND", getString(gc.get(Calendar.MILLISECOND), 3, "0"));
    // tokens.put("ZONE_OFFSET", getString((gc.get(Calendar.ZONE_OFFSET)/(60*60*1000)), 0, ""));
    // tokens.put("DST_OFFSET", getString((gc.get(Calendar.DST_OFFSET)/(60*60*1000)), 0, ""));
    tokens.put("COUNTER", getString(counter, 0, ""));

    return processParams(path, tokens);
}

From source file:de.innovationgate.utils.WGUtils.java

/**
 * Removes daytime information from a date, leaving date information only
 * @param date The date to strip daytime information from
 * @return The date only date object/*w  w  w  .  j a  v a  2 s  .  c om*/
 */
public static Date dateOnly(Date date) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.AM_PM, 0);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();

}

From source file:org.kuali.kfs.module.purap.document.service.impl.PurchaseOrderServiceImpl.java

/**
 * Creates and returns a Calendar object of today minus three months.
 *
 * @return Calendar object of today minus three months.
 *///from w  ww .j a va  2  s.c  o  m
protected Calendar getTodayMinusThreeMonths() {
    Calendar todayMinusThreeMonths = Calendar.getInstance(); // Set to today.
    todayMinusThreeMonths.add(Calendar.MONTH, -3); // Back up 3 months.
    todayMinusThreeMonths.set(Calendar.HOUR, 12);
    todayMinusThreeMonths.set(Calendar.MINUTE, 0);
    todayMinusThreeMonths.set(Calendar.SECOND, 0);
    todayMinusThreeMonths.set(Calendar.MILLISECOND, 0);
    todayMinusThreeMonths.set(Calendar.AM_PM, Calendar.AM);
    return todayMinusThreeMonths;
}

From source file:semlink.apps.uvig.Generator.java

/**
 * Replaces all special sequences in a given line of text with corresponding
 * real-world values.  The available special sequences are: <CODE>@@browser-title@@</CODE>,
 * <CODE>@@page-title@@</CODE>, <CODE>@@license@@</CODE>, <CODE>@@date@@</CODE>, and
 * <CODE>@@time@@</CODE>.  More details about these are supplied in the README file.
 *
 * @param line the line which requires replacement of any existing special sequences
 * @param fileName the name of the file that the line came from.  This will be
 *        used to determine exactly how to replace certain sequences, since
 *        different files will need to display different information around their
 *        borders.//w ww . j a  v  a2 s.c o  m
 * @see uvi.Generator#createHTMLOutStream(String, String, String)
 * @see uvi.Generator#closeHTMLOutStream(PrintWriter, String)
 */
private static String replaceSpecialSequences(String line, String fileName) {
    String n;
    String flavor = getProperty("vnFlavorName", "VerbNet");

    // Just examine the file name portion (there could be
    // a directory on here).
    fileName = fileName.substring(fileName.lastIndexOf('/') + 1);

    // Remove the extension of a file name to get an OK title for the file.
    if (fileName.lastIndexOf(".") == -1) {
        n = fileName;
    } else {
        n = fileName.substring(0, fileName.lastIndexOf("."));
    }

    // Replace the special tokens based on whether the file in question
    // is an index page or a VerbNet page.
    if (fileName.matches("index\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index");
        line = line.replaceAll("@@page-title@@", "&nbsp;");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='vn/reference.php'>Reference</A> | <A href='vn/class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }

        String contact = "<A href='contact.php'>Contact</A>";
        if (!flNoInsp) {
            contact += " | <A href='inspector/'>Inspector</A>";
        }
        if (!flNoVxC) {
            contact += " | <A href='vxc/'>VxC</A>";
        }
        if (!flNoGen) {
            contact += " | <A href='generator/'>Generator</A>";
        }

        line = line.replaceAll("@@license@@", contact);
    } else if (fileName.matches("[A-Z]\\.php")) {
        line = line.replaceAll("@@rel-dir@@", "..");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: " + n);
        line = line.replaceAll("@@page-title@@", "Unified Verb Index");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='../vn/reference.php'>Reference</A> | <A href='../vn/class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }

        String contact = "<A href='contact.php'>Contact</A>";
        if (!flNoInsp) {
            contact += " | <A href='../inspector/'>Inspector</A>";
        }
        if (!flNoVxC) {
            contact += " | <A href='../vxc/'>VxC</A>";
        }
        if (!flNoGen) {
            contact += " | <A href='../generator/'>Generator</A>";
        }

        line = line.replaceAll("@@license@@", contact);
    } else if (fileName.matches("contact\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: Contact");
        line = line.replaceAll("@@page-title@@", "Contact Information");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='vn/reference.php'>Reference</A> | <A href='vn/class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }

        String contact = "<A href='contact.php'>Contact</A>";
        if (!flNoInsp) {
            contact += " | <A href='inspector/'>Inspector</A>";
        }
        if (!flNoVxC) {
            contact += " | <A href='vxc/'>VxC</A>";
        }
        if (!flNoGen) {
            contact += " | <A href='generator/'>Generator</A>";
        }

        line = line.replaceAll("@@license@@", contact);
    } else if (fileName.matches("search\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: Search");
        line = line.replaceAll("@@page-title@@", "Search");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='vn/reference.php'>Reference</A> | <A href='vn/class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }

        String contact = "<A href='contact.php'>Contact</A>";
        if (!flNoInsp) {
            contact += " | <A href='inspector/'>Inspector</A>";
        }
        if (!flNoVxC) {
            contact += " | <A href='vxc/'>VxC</A>";
        }
        if (!flNoGen) {
            contact += " | <A href='generator/'>Generator</A>";
        }

        line = line.replaceAll("@@license@@", contact);
    } else if (fileName.matches("postcomment\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: Post Comment");
        line = line.replaceAll("@@page-title@@", "Post A Comment");
        line = line.replaceAll("@@license@@", "&nbsp;");
        line = line.replaceAll("@@footer-links@@", "&nbsp;");
    } else if (fileName.matches("comments\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: Comments");
        line = line.replaceAll("@@page-title@@", "View and Delete Comments");
        line = line.replaceAll("@@license@@", "&nbsp;");
        line = line.replaceAll("@@footer-links@@", "&nbsp;");
    } else if (fileName.matches("login\\.php")) {
        line = line.replaceAll("@@rel-dir@@", ".");
        line = line.replaceAll("@@browser-title@@", "Unified Verb Index: Login");
        line = line.replaceAll("@@page-title@@", "Login");
        line = line.replaceAll("@@license@@", "&nbsp;");
        line = line.replaceAll("@@footer-links@@", "&nbsp;");
    } else if (fileName.matches("reference\\.php")) {
        String contact = "<A href='../contact.php'>Contact</A>";
        line = line.replaceAll("@@rel-dir@@", "..");
        line = line.replaceAll("@@browser-title@@", flavor + " Reference Page");
        line = line.replaceAll("@@page-title@@", flavor + " Reference Page");
        line = line.replaceAll("@@license@@", contact + " | <A href='http://verbs.colorado.edu/~mpalmer/"
                + "projects/verbnet/downloads.html'>VerbNet Download &amp; License</A>");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='reference.php'>Reference</A> | <A href='class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }
    } else if (fileName.matches("class-h\\.php")) {
        String contact = "<A href='../contact.php'>Contact</A>";
        line = line.replaceAll("@@rel-dir@@", "..");
        line = line.replaceAll("@@browser-title@@", flavor + " Class Hierarchy");
        line = line.replaceAll("@@page-title@@", flavor + " Class Hierarchy");
        line = line.replaceAll("@@license@@", contact + " | <A href='http://verbs.colorado.edu/~mpalmer/"
                + "projects/verbnet/downloads.html'>VerbNet Download &amp; License</A>");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='reference.php'>Reference</A> | <A href='class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }
    } else // All VerbNet class files will fall into here, and a few other files as well (i.e. those that don't use @@ tokens).
    {
        String contact = "<A href='../contact.php'>Contact</A>";
        line = line.replaceAll("@@rel-dir@@", "..");
        line = line.replaceAll("@@browser-title@@", flavor + ": " + n);
        line = line.replaceAll("@@page-title@@", flavor + " v" + getProperty("vnVersion", "?"));
        line = line.replaceAll("@@license@@", contact + " | <A href='http://verbs.colorado.edu/~mpalmer/"
                + "projects/verbnet/downloads.html'>VerbNet Download &amp; License</A>");
        if (!flNoIndexVn) {
            line = line.replaceAll("@@footer-links@@",
                    "<A href='../vn/reference.php'>Reference</A> | <A href='../vn/class-h.php'>Class Hierarchy</A>");
        } else {
            line = line.replaceAll("@@footer-links@@", "&nbsp;");
        }
    }

    // Replace the special token with the current date.
    if (line.indexOf("@@date@@") != -1) {
        String d = runTime.get(Calendar.YEAR) + "." + (runTime.get(Calendar.MONTH) + 1) + "."
                + runTime.get(Calendar.DAY_OF_MONTH);

        line = line.replaceAll("@@date@@", d);
    }

    // Replace the special token with the current time.
    if (line.indexOf("@@time@@") != -1) {
        String maintNotesLink;
        if (fileName.matches("index\\.php")) {
            maintNotesLink = "<A href='maint-notes.html' style='font-weight:normal;color:white;'>M</A>";
        } else {
            maintNotesLink = "M";
        }
        String ap = ((runTime.get(Calendar.AM_PM) == 0) ? "A" : "P") + maintNotesLink;
        String h = (runTime.get(Calendar.HOUR) == 0) ? "12" : "" + runTime.get(Calendar.HOUR);
        String m = (runTime.get(Calendar.MINUTE) < 10) ? "0" + runTime.get(Calendar.MINUTE)
                : "" + runTime.get(Calendar.MINUTE);

        String t = h + ":" + m + " " + ap;

        line = line.replaceAll("@@time@@", t);
    }

    return line;
}

From source file:com.clark.func.Functions.java

/**
 * <p>/*from   w w w . j a v  a 2s .  c  o m*/
 * Internal calculation method.
 * </p>
 * 
 * @param val
 *            the calendar
 * @param field
 *            the field constant
 * @param modType
 *            type to truncate, round or ceiling
 * @throws ArithmeticException
 *             if the year is over 280 million
 */
private static void modifyDate(Calendar val, int field, int modType) {
    if (val.get(Calendar.YEAR) > 280000000) {
        throw new ArithmeticException("Calendar value too large for accurate calculations");
    }

    if (field == Calendar.MILLISECOND) {
        return;
    }

    // ----------------- Fix for LANG-59 ---------------------- START
    // ---------------
    // see http://issues.apache.org/jira/browse/LANG-59
    //
    // Manually truncate milliseconds, seconds and minutes, rather than
    // using
    // Calendar methods.

    Date date = val.getTime();
    long time = date.getTime();
    boolean done = false;

    // truncate milliseconds
    int millisecs = val.get(Calendar.MILLISECOND);
    if (MODIFY_TRUNCATE == modType || millisecs < 500) {
        time = time - millisecs;
    }
    if (field == Calendar.SECOND) {
        done = true;
    }

    // truncate seconds
    int seconds = val.get(Calendar.SECOND);
    if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
        time = time - (seconds * 1000L);
    }
    if (field == Calendar.MINUTE) {
        done = true;
    }

    // truncate minutes
    int minutes = val.get(Calendar.MINUTE);
    if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
        time = time - (minutes * 60000L);
    }

    // reset time
    if (date.getTime() != time) {
        date.setTime(time);
        val.setTime(date);
    }
    // ----------------- Fix for LANG-59 ----------------------- END
    // ----------------

    boolean roundUp = false;
    for (int i = 0; i < fields.length; i++) {
        for (int j = 0; j < fields[i].length; j++) {
            if (fields[i][j] == field) {
                // This is our field... we stop looping
                if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
                    if (field == SEMI_MONTH) {
                        // This is a special case that's hard to generalize
                        // If the date is 1, we round up to 16, otherwise
                        // we subtract 15 days and add 1 month
                        if (val.get(Calendar.DATE) == 1) {
                            val.add(Calendar.DATE, 15);
                        } else {
                            val.add(Calendar.DATE, -15);
                            val.add(Calendar.MONTH, 1);
                        }
                        // ----------------- Fix for LANG-440
                        // ---------------------- START ---------------
                    } else if (field == Calendar.AM_PM) {
                        // This is a special case
                        // If the time is 0, we round up to 12, otherwise
                        // we subtract 12 hours and add 1 day
                        if (val.get(Calendar.HOUR_OF_DAY) == 0) {
                            val.add(Calendar.HOUR_OF_DAY, 12);
                        } else {
                            val.add(Calendar.HOUR_OF_DAY, -12);
                            val.add(Calendar.DATE, 1);
                        }
                        // ----------------- Fix for LANG-440
                        // ---------------------- END ---------------
                    } else {
                        // We need at add one to this field since the
                        // last number causes us to round up
                        val.add(fields[i][0], 1);
                    }
                }
                return;
            }
        }
        // We have various fields that are not easy roundings
        int offset = 0;
        boolean offsetSet = false;
        // These are special types of fields that require different rounding
        // rules
        switch (field) {
        case SEMI_MONTH:
            if (fields[i][0] == Calendar.DATE) {
                // If we're going to drop the DATE field's value,
                // we want to do this our own way.
                // We need to subtrace 1 since the date has a minimum of
                // 1
                offset = val.get(Calendar.DATE) - 1;
                // If we're above 15 days adjustment, that means we're
                // in
                // the
                // bottom half of the month and should stay accordingly.
                if (offset >= 15) {
                    offset -= 15;
                }
                // Record whether we're in the top or bottom half of
                // that
                // range
                roundUp = offset > 7;
                offsetSet = true;
            }
            break;
        case Calendar.AM_PM:
            if (fields[i][0] == Calendar.HOUR_OF_DAY) {
                // If we're going to drop the HOUR field's value,
                // we want to do this our own way.
                offset = val.get(Calendar.HOUR_OF_DAY);
                if (offset >= 12) {
                    offset -= 12;
                }
                roundUp = offset >= 6;
                offsetSet = true;
            }
            break;
        }
        if (!offsetSet) {
            int min = val.getActualMinimum(fields[i][0]);
            int max = val.getActualMaximum(fields[i][0]);
            // Calculate the offset from the minimum allowed value
            offset = val.get(fields[i][0]) - min;
            // Set roundUp if this is more than half way between the minimum
            // and maximum
            roundUp = offset > ((max - min) / 2);
        }
        // We need to remove this field
        if (offset != 0) {
            val.set(fields[i][0], val.get(fields[i][0]) - offset);
        }
    }
    throw new IllegalArgumentException("The field " + field + " is not supported");

}