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

StringgetTimestampFormat(long time)
get Timestamp Format
try {
    return timestamp.format(new Date(time));
} catch (Exception e) {
    return "cant figure out (" + time + ")";
StringsortedTimestampFormat(Date date)
sorted Timestamp Format
return getSortedTimetampFormat().format(date);
intstringConvertToTimestamp(String value, String format)
string Convert To Timestamp
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = null;
try {
    date = simpleDateFormat.parse(value);
} catch (ParseException e) {
return (int) (date.getTime() / 1000);
StringTimeStamp2Date(long timestampString, String formats)
Time Stamp Date
Long timestamp = timestampString;
String date = new SimpleDateFormat(formats).format(new Date(timestamp));
return date;
StringtimeStamp2Date(String seconds, String format)
time Stamp Date
if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
    return "";
if (format == null || format.isEmpty())
    format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds)));
StringTimestamp2DDMMYYYY(java.sql.Timestamp ts)
Timestamp DDMMYYYY
if (ts == null) {
    return "";
} else {
    java.util.Calendar calendar = java.util.Calendar.getInstance();
    calendar.setTime(new java.util.Date(ts.getTime()));
    String strTemp = Integer.toString(calendar.get(calendar.DAY_OF_MONTH));
    if (calendar.get(calendar.DAY_OF_MONTH) < 10) {
        strTemp = "0" + strTemp;
...
StringTimestamp2HHMMSS(java.sql.Timestamp ts, int iStyle)
Timestamp HHMMSS
if (ts == null) {
    return "";
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setTime(new java.util.Date(ts.getTime()));
String strTemp;
if (iStyle == 0) {
    strTemp = Integer.toString(calendar.get(calendar.HOUR_OF_DAY));
...
Stringtimestamp2String(long source, DateFormat format)
timestamp String
return date2String(timestamp2Date(source), format);
StringTimestamp2UTC(Timestamp mytime)
Converts a java.util.Timestamp to UTC needed if the "Generalized Time Syntax Plug-in" of FedoraDS is not enabled
Timestamp b = new Timestamp(mytime.getTime());
SimpleDateFormat mySimpleFormat = new SimpleDateFormat("yyyyMMddHHmmss");
mySimpleFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String ret = mySimpleFormat.format(b) + "Z";
return ret;
StringtimestampConvertToString(int timeStamp, String format)
timestamp Convert To String
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
long lTime = Long.valueOf(timeStamp);
return simpleDateFormat.format(new Date(lTime * 1000));