Java Timestamp Format getFullTimestampFormatter(Locale locale)

Here you can find the source of getFullTimestampFormatter(Locale locale)

Description

get Full Timestamp Formatter

License

Open Source License

Declaration

public static DateFormat getFullTimestampFormatter(Locale locale) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Locale;

public class Main {
    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static DateFormat getFullTimestampFormatter(Locale locale) {
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);

        String localeString = locale.toString();
        if (localeString.equals("zh_SG")) {
            return new SimpleDateFormat("dd/MM/yyyy a hh:mm");
        } else if (localeString.equals("ko")) {
            return changeDateFormatPattern(dateFormat, "y+\\. *M+\\. *d+", "yyyy-MM-dd");
        }/*from w  w  w .ja v a 2  s.  c  o  m*/

        // change year format to long format (e.g. 2012)
        return changeDateFormatPattern(dateFormat, "y+", "yyyy");
    }

    public static SimpleDateFormat getFullTimestampFormatter() {
        return new SimpleDateFormat(DATE_TIME_FORMAT); // m_fullTimestampFormatter;
    }

    private static DateFormat changeDateFormatPattern(final DateFormat dateFormat, String regex,
            String replacement) {
        if (dateFormat instanceof SimpleDateFormat) {
            SimpleDateFormat simpleDateFormat = (SimpleDateFormat) dateFormat;

            String pattern = simpleDateFormat.toPattern().replaceAll(regex, replacement);
            simpleDateFormat.applyPattern(pattern);

            return simpleDateFormat;
        }
        return dateFormat;
    }
}

Related

  1. getFormattedTime(long timestamp, String format)
  2. getFormattedTimestamp()
  3. getFormattedTimestamp(@Nonnull Date date)
  4. getFormattedTimestamp(File file)
  5. getFormattedTimeStamp(long timestamp, String formatString)
  6. getTimestamp(boolean useTwentyFourFormat)
  7. getTimeStamp(String format)
  8. getTimestamp(String format)
  9. getTimestampFormat()