Java Utililty Methods Timestamp Format

List of utility methods to do Timestamp Format

Description

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

Method

StringformatTimestamp(Timestamp ts, int dateStyle, int timeStyle, Locale locale)
Einen Timestamp localeabhaengig formatieren.
return DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale).format(ts);
StringformatTimeStampMsec(long epochTime)
format Time Stamp Msec
return TIME_FORMAT_MSEC.format(new Date(epochTime));
StringformatTimestampTime(Timestamp ts, boolean colon)
format Timestamp Time
String tstr;
Calendar c = Calendar.getInstance();
c.setTimeInMillis(ts.getTime());
int hours = c.get(Calendar.HOUR_OF_DAY);
if (hours > 12)
    hours -= 12;
if (hours == 0)
    hours = 12;
...
StringformatTimestampToIndex(java.sql.Timestamp timestamp)
formatTimestampToIndex Call this function to format a java.sql.Timestamp into a String with format "yyyyMMddhhmmss" for lucene indexing
if (timestamp == null) {
    return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss", java.util.Locale.US);
String dateStr = sdf.format(timestamp);
return dateStr;
longformatTimestampToLong(final String timestampStr)
format Timestamp To Long
Date date;
try {
    date = getTimestampFormat().parse(timestampStr);
} catch (final ParseException e) {
    return 0L;
return date.getTime();
StringformatTimestampWithSlashes(java.sql.Timestamp tsZeitpunkt)
format Timestamp With Slashes
if (tsZeitpunkt != null) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(tsZeitpunkt.getTime());
    String s = "";
    int iMonat = cal.get(Calendar.MONTH) + 1;
    s = cal.get(Calendar.DAY_OF_MONTH) + "/" + iMonat + "/" + cal.get(Calendar.YEAR) + " "
            + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":"
            + cal.get(Calendar.SECOND) + "."
...
StringformatTimeToString(long timestamp)
format Time To String
DateFormat sdf = timef.get();
if (sdf == null) {
    sdf = new SimpleDateFormat(ES_DATE_FORMAT);
    timef.set(sdf);
return sdf.format(timestamp);
longformatToLong(String format)
format To Long
SimpleDateFormat f = new SimpleDateFormat(format);
return Timestamp.valueOf(f.format(new Date())).getTime();
StringformatToString(long timestamp, String datePattern)
Take a timestamp, and turn it into a string with the specified format.
return (new Timestamp(timestamp * 1000).toLocalDateTime()).format(DateTimeFormatter.ofPattern(datePattern));
ObjectformatValue(Object obj, boolean isboolean)
format Value
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;