Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

In this page you can find the example usage for java.text DateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java

/**
 * Creation d'une mesure de type Kiviat pour un projet
 * //w  w w. j  a v  a2 s .c o m
 * @param pProjectId Id du projet
 * @param pAuditId Id de l'audit
 * @param pAllFactors tous les facteurs (= "true") ou seulement ceux ayant une note ?
 * @throws JrafEnterpriseException en cas de pb Hibernate
 * @return tableau d'objets : la map des donnes + le boolen pour affichage de la case  cocher tous les facteurs
 */
public static Object[] getProjectKiviat(Long pProjectId, Long pAuditId, String pAllFactors)
        throws JrafEnterpriseException {
    Map result = new HashMap();
    JFreeChart projectKiviat = null;
    MeasureDAOImpl measureDAO = MeasureDAOImpl.getInstance();
    // Session Hibernate
    ISession session = null;
    // Boolen conditonnanant l'affichage de la case  cocher "tous les facteurs" dans la page Jsp
    boolean displayCheckBoxFactors = true;
    try {
        // rcupration d'une session
        session = PERSISTENTPROVIDER.getSession();
        // On ajoute les notes de chaque projets sur le kiviat
        ProjectBO project = (ProjectBO) ProjectDAOImpl.getInstance().load(session, pProjectId);
        SortedMap values = new TreeMap();
        // recupere les facteurs du projet
        Collection factorResults = QualityResultDAOImpl.getInstance().findWhere(session, pProjectId, pAuditId);
        // et cree le map nom => note correspondant
        Iterator it = factorResults.iterator();
        ArrayList nullValuesList = new ArrayList();
        while (it.hasNext()) {
            FactorResultBO factor = (FactorResultBO) it.next();
            // le -1 est trait directement par le kiviatMaker
            Float value = new Float(factor.getMeanMark());
            // ajoute la note dans le titre
            // TODO prendre le vritable nom du facteur
            String name = factor.getRule().getName();
            if (value.floatValue() >= 0) {
                // avec 1 seul chiffre aprs la virgule
                NumberFormat nf = NumberFormat.getInstance();
                nf.setMinimumFractionDigits(1);
                nf.setMaximumFractionDigits(1);
                name = name + " (" + nf.format(value) + ")";
            } else {
                // Mmorisation temporaire des facteurs pour lesquels les notes sont nulles : sera utile si l'option
                // "Tous les facteurs" est coche pour afficher uniquement les facteurs ayant une note.
                nullValuesList.add(name);
            }
            values.put(name, value);
        }
        final int FACTORS_MIN = 3;
        if (nullValuesList.size() <= 0 || values.size() <= FACTORS_MIN) {
            displayCheckBoxFactors = false;
        }
        // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle.
        // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !)
        values = deleteFactors(values, nullValuesList, pAllFactors, FACTORS_MIN);

        // recupre le nom de l'audit
        String name = null;
        AuditBO audit = (AuditBO) AuditDAOImpl.getInstance().load(session, pAuditId);
        if (audit.getType().compareTo(AuditBO.MILESTONE) == 0) {
            name = audit.getName();
        }
        if (null == name) {
            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
            name = df.format(audit.getDate());
        }
        result.put(name, values);

    } catch (Exception e) {
        FacadeHelper.convertException(e, MeasureFacade.class.getName() + ".getMeasures");
    } finally {
        FacadeHelper.closeSession(session, MeasureFacade.class.getName() + ".getMeasures");
    }
    Object[] kiviatObject = { result, new Boolean(displayCheckBoxFactors) };
    return kiviatObject;
}

From source file:ch.ralscha.extdirectspring_itest.SecuredService.java

@ExtDirectMethod(group = "secured")
@PreAuthorize("isAnonymous()")
public String setDate(String id, @DateTimeFormat(pattern = "dd/MM/yyyy") Date date,
        @AuthenticationPrincipal UserDetails ud) {
    DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    return id + "," + dateFormat.format(date) + "," + (ud != null ? ud.getUsername() : "");
}

From source file:com.ewcms.publication.freemarker.directive.out.DateDirectiveOut.java

@SuppressWarnings("rawtypes")
@Override// ww  w .j  a v  a  2  s  . com
public String constructOut(Object value, Environment env, Map params) throws TemplateException {
    Assert.notNull(value);
    DateFormat dateFormat = getDateFormat(params);
    return dateFormat.format(value);
}

From source file:com.iisi.DAO.M06aProcessor.java

@Override
public M06a process(M06a m06a) throws Exception {
    m06a.setLicensePlate(m06a.getDetectionOrigin() + "-" + m06a.getLineNum());
    String time = m06a.getDetectionOrigin();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(time);//from  www  .  j  a  v  a 2  s .c o  m
    m06a.setYmd(sdf2.format(date));

    return m06a;

}

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * Converts une java.sql.Timestamp date in a String date in a "jj/mm/aaaa" format
 *
 * @param date java.sql.Timestamp date to convert
 * @param locale the locale// www  . java2 s  . c om
 * @return strDate The String date in the short locale format or the emmpty String if the date is null
 * @deprecated
 */
public static String getDateString(Timestamp date, Locale locale) {
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);

    return dateFormat.format(date);
}

From source file:com.codenvy.dev.shell.view.ShellPromptProvider.java

@Override
public String getPrompt() {
    DateFormat dateFormat = new SimpleDateFormat("HH:mm");

    return String.format("[%s] :: codenvy dev $", dateFormat.format(Calendar.getInstance().getTime()));
}

From source file:cz.fi.muni.pa165.presentation.layer.mvc.aspect.LoggingAspect.java

@Before("allCreateMethods() || allDeleteMethods()")
private void logMethodExecution(JoinPoint point) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String currentTime = dateFormat.format(new Date());

    String method = point.getSignature().getName();
    String target = point.getTarget().getClass().getSimpleName();
    logger.error("Method of " + target + ": " + method + " at " + currentTime + " executed.");
}

From source file:com.acuityph.commons.logging.SimpleFormatter.java

/**
 * {@inheritDoc}/*from  w  w w . ja v a2  s . c o m*/
 *
 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
 */
@Override
public final String format(final LogRecord logRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(LEVELS_MAP.get(logRecord.getLevel()));
    final DateFormat sdf = DateFormat.getDateTimeInstance();
    sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' ');
    sb.append(getShortName(logRecord.getSourceClassName()));
    sb.append('.').append(logRecord.getSourceMethodName()).append(": ");
    sb.append(logRecord.getMessage()).append("\n");
    return sb.toString();
}

From source file:org.consultjr.mvc.core.components.formatters.DateFormatter.java

@Override
public String print(Date object, Locale locale) {
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {//from www.  j a  v  a 2s . co  m
        return formatter.format(object).toString();
    } catch (Exception ex) {
        Logger.getLogger(DateFormatter.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:com.adito.tasks.shutdown.ShutdownTimerTask.java

/**
 * @return String/*from   w w  w. j a  v  a 2s .  c  o m*/
 */
public String getShutDownTimeString() {
    DateFormat format = new SimpleDateFormat("HH:mm");
    return format.format(getShutDownTime());
}