Java Date Format As fmtMsg(final String fmt, final String arg)

Here you can find the source of fmtMsg(final String fmt, final String arg)

Description

Format a message consisting of a format string

License

Apache License

Parameter

Parameter Description
fmt a parameter
arg a parameter

Return

String formatted message

Declaration

public static String fmtMsg(final String fmt, final String arg) 

Method Source Code

//package com.java2s;
/* ********************************************************************
Licensed to Jasig under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Jasig licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a
copy of the License at://w w  w .j a va 2 s .c o  m
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

import java.text.MessageFormat;

public class Main {
    /** Format a message consisting of a format string
     *
     * @param fmt
     * @param arg
     * @return String formatted message
     */
    public static String fmtMsg(final String fmt, final String arg) {
        Object[] o = new Object[1];
        o[0] = arg;

        return MessageFormat.format(fmt, o);
    }

    /** Format a message consisting of a format string plus two string parameters
     *
     * @param fmt
     * @param arg1
     * @param arg2
     * @return String formatted message
     */
    public static String fmtMsg(final String fmt, final String arg1, final String arg2) {
        Object[] o = new Object[2];
        o[0] = arg1;
        o[1] = arg2;

        return MessageFormat.format(fmt, o);
    }

    /** Format a message consisting of a format string plus one integer parameter
     *
     * @param fmt
     * @param arg
     * @return String formatted message
     */
    public static String fmtMsg(final String fmt, final int arg) {
        Object[] o = new Object[1];
        o[0] = new Integer(arg);

        return MessageFormat.format(fmt, o);
    }
}

Related

  1. fmt(String pattern, Object... args)
  2. fmtBdToString(BigDecimal bd, DecimalFormat df)
  3. fmtDate(Date date)
  4. fmtDate(Date date)
  5. fmtDateTime(final Date dateTime, final String simpleDateTimeFormat)
  6. fmtNumStringToDouble(String s)
  7. fmtTime(Date time)
  8. formatDateAccordingToSessionDuration(Calendar cal, int sessionDuration, int offset)
  9. formatDateAppello(Date data)