Code example for SimpleDateFormat

Methods: format

0
        if (args.length >= 1) {
            Object o1 = args[0];
            if (args.length == 2 && args[1] instanceof String) {
                Object o2 = args[1];
                if (o1 instanceof Calendar || o1 instanceof Date) {
                    DateFormat formatter = new SimpleDateFormat((String) o2);
                    return formatter.format(o1 instanceof Date ? ((Date) o1) : ((Calendar) o1).getTime());
                } else if (o1 instanceof Number) {
                    return String.format((String) o2, (Number) o1);
                } 
            } else if (args.length == 1) {
                if (o1 instanceof String) {
                    return (String) o1;
                } else { 
                    return StringUtils.toString(o1);
                }  
            } 
        } 
        return new EvalError("ToString accepts an object and an optional second argument containing a date format string"); 
    } 
Experience pair programming with AI  Get Codota for Java