Java Utililty Methods Date Format Pattern

List of utility methods to do Date Format Pattern

Description

The list of methods to do Date Format Pattern are organized into topic(s).

Method

StringgetStringAcordFormat()
get String Acord Format
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
int currentOffset = myFormatter.getTimeZone().getRawOffset();
long diff = currentOffset + 18000000;
Date currentDate = new Date(System.currentTimeMillis() - diff);
String myFormattedDate = myFormatter.format(currentDate);
return myFormattedDate;
SimpleDateFormat[]getSupportedFormats()
get Supported Formats
return new SimpleDateFormat[] { rfc1123, rfc850, asctime };
booleanisEqual(String d1, String d2, String format)
is Equal
Date d1Date = toDate(d1, format);
Date d2Date = toDate(d2, format);
if (d1Date.getTime() == d2Date.getTime())
    return true;
return false;
booleanisValidFormat(String format, String value)
Date string format validate
Date date = null;
try {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    formatter.setLenient(false); 
    date = formatter.parse(value);
} catch (ParseException ex) {
    return false;
return date != null;
voidlog(String format, Object... args)
log
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement callee = stack[2];
String calleeClassname = callee.getClassName();
String timestamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
System.err.printf(timestamp + " " + calleeClassname + ": " + format, args);
StringlogFormat(String msg)
log Format
DateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
Date date = new Date();
String[] messageDisplay = msg.replaceFirst("]", "string that should never match")
        .split("string that should never match");
return dateFormat.format(date) + " " + messageDisplay[1];
voidsubFiles(String formatString, File[] files)
Gets a list of backups
for (File file : files) {
    if (file.isDirectory()) {
        subFiles(formatString, file.listFiles()); 
    } else {
        if (file.getName().endsWith(".zip")) {
            String dateString = file.getName();
            DateFormat format = new SimpleDateFormat(formatString, Locale.ENGLISH);
            try {
...
doublesubtraiHora(String horaFim, String horaIni, String formatoHora)
Retorna o numero de minutos
SimpleDateFormat formatter = new SimpleDateFormat(formatoHora);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
double min_1 = 0;
double min_2 = 0;
double result = 0;
min_1 = getHoras(horaFim, formatter);
min_2 = getHoras(horaIni, formatter);
result = (min_1 - min_2) * 60;
...
StringsysdateStringddMMyyyyhhmmss()
sysdate Stringdd M Myyyyhhmmss
SimpleDateFormat dbUpdateDateTime = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return dbUpdateDateTime.format(new Date());
ThreadLocaltoThreadSafeFormat(final String format)
to Thread Safe Format
return new ThreadLocal<SimpleDateFormat>() {
    @Override
    protected SimpleDateFormat initialValue() {
        return new SimpleDateFormat(format);
};