Java Hour Format formatUIDate(Calendar calendar)

Here you can find the source of formatUIDate(Calendar calendar)

Description

Utility routine that takes in a Calendar referece and returns a date/time stamp suitable for use in a Portlets environment.

License

Open Source License

Parameter

Parameter Description
calendar a parameter

Return

Date/timestamp suitable for display.

Declaration

public static String formatUIDate(Calendar calendar) 

Method Source Code

//package com.java2s;
/*/*from w  w w.  j  a v a  2  s  .  c  o m*/
 * Copyright (c) 2004-2012 The YAWL Foundation. All rights reserved.
 * The YAWL Foundation is a collaboration of individuals and
 * organisations who are committed to improving workflow technology.
 *
 * This file is part of YAWL. YAWL is free software: you can
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 *
 * YAWL is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with YAWL. If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     * Utility routine that takes in a Calendar referece and returns a date/time stamp suitable for use
     * in a Portlets environment.
     *
     * @param calendar
     * @return Date/timestamp suitable for display.
     * @deprecated Use TimeUtil.formatUIDate
     */
    public static String formatUIDate(Calendar calendar) {
        SimpleDateFormat fmt = null;

        /**
         * Set format depending upon whether we have a timestamp component to the calendar.
         * Ok, this is slightly flawed as an assumption as we could be bang on midnight.......
         */
        if ((calendar.get(Calendar.HOUR) == 0) && (calendar.get(Calendar.MINUTE) == 0)
                && (calendar.get(Calendar.SECOND) == 0)) {
            fmt = new SimpleDateFormat("dd-MMM-yy");
        } else {
            fmt = new SimpleDateFormat("dd-MMM-yy hh:mm a");
        }

        return fmt.format(calendar.getTime());
    }
}

Related

  1. formatTime_2(long time_value, long frame_rate)
  2. formatToHour(Date date)
  3. formatToOpenMrsDate(Date date)
  4. formatToSec(Date date)
  5. formatToString(Date date)
  6. formatUnixFileListing(final Date d)
  7. formatUnsignedVersion(String ver)
  8. formatValue(Object value)
  9. formatVerbose(int level, String message, String source)