Java Timestamp Format formatValue(Object obj, boolean isboolean)

Here you can find the source of formatValue(Object obj, boolean isboolean)

Description

format Value

License

Apache License

Declaration

public static Object formatValue(Object obj, boolean isboolean) 

Method Source Code

//package com.java2s;
/*/*from w  ww .j av a  2 s  .  co  m*/
 Licensed to Diennea S.r.l. under one
 or more contributor license agreements. See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership. Diennea S.r.l. 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
    
 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.
    
 */

public class Main {
    public static Object formatValue(Object obj) {
        return formatValue(obj, false);
    }

    public static Object formatValue(Object obj, boolean isboolean) {
        if (isboolean) {
            if (obj instanceof Integer) {
                Integer bj = (Integer) obj;
                if (bj == 0) {
                    return getBoolean(false);
                } else if (bj == 1) {
                    return getBoolean(true);
                }
            }
            if (obj instanceof Boolean) {
                Boolean bj = (Boolean) obj;
                return getBoolean(bj);
            }
            if (obj instanceof String) {
                String bj = (String) obj;
                if (bj.equalsIgnoreCase("true")) {
                    return getBoolean(true);
                } else if (bj.equalsIgnoreCase("false")) {
                    return getBoolean(false);
                }
            }
        }
        if (obj instanceof java.sql.Date || obj instanceof java.sql.Timestamp) {
            return obj.toString();
        }
        return obj;
    }

    private static String getBoolean(boolean bool) {
        if (bool) {
            return "<span><i class='ti-check' style='color: green'></i></span>";
        } else {
            return "<span><i class='ti-close' style='color: red'></i></span>";
        }
    }
}

Related

  1. formatTimestampToLong(final String timestampStr)
  2. formatTimestampWithSlashes( java.sql.Timestamp tsZeitpunkt)
  3. formatTimeToString(long timestamp)
  4. formatToLong(String format)
  5. formatToString(long timestamp, String datePattern)
  6. friendlyTimestamp(Date date)
  7. friendlyTimestampFormat()
  8. friendlyTimestampFormat()
  9. getCalendar(String timeStamp, final String dateFormat)