Java Utililty Methods Timestamp Create

List of utility methods to do Timestamp Create

Description

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

Method

TimestampgetTimestampNullSafe(final Date ts)
get Timestamp Null Safe
return (ts == null) ? null : new Timestamp(ts.getTime());
TimestampgetTimestampOrNull(Object dbResult)
Convenience method to format dbResult
if (dbResult == null) {
    return null;
return (Timestamp) dbResult;
StringgetTimeStampString()
get Time Stamp String
Date date = new Date();
timestamp = DateFormat.getDateTimeInstance().format(date);
return timestamp;
StringgetTimestampString(long timeInMillis)
get Timestamp String
Timestamp ts = new Timestamp(timeInMillis);
String tsStr = ts.toString().substring(0, 19) + "-0" + ts.getTimezoneOffset() / 60 + "00";
return tsStr;
StringgetTimeStampStringFormat(Timestamp ts, String fmt)
get Time Stamp String Format
String result = "";
LinkedList<String> fmtList = new LinkedList<String>();
LinkedList<String> valList = new LinkedList<String>();
fmtList.clear();
valList.clear();
result = ts.toString();
fmtList.add("yyyy");
valList.add(result.substring(0, 4));
...
StringgetTimestampToOracle()
get Timestamp To Oracle
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(System.currentTimeMillis());
TimestampgetTimestampXDaysFromY(long startTimeInMillis, int daysFromStartDate)
get Timestamp X Days From Y
Calendar cal = getCalendarXDaysFromY(startTimeInMillis, daysFromStartDate);
return new Timestamp(cal.getTimeInMillis());
StringgetTimeStrByTimestamp(long timestamp, String tz)
get Time Str By Timestamp
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
SimpleDateFormat dateFormatGmt = new SimpleDateFormat(DATE_FORMAT);
dateFormatGmt.setTimeZone(TimeZone.getTimeZone(tz));
return dateFormatGmt.format(calendar.getTime());
longtimestamp()
timestamp
return timestampStartOfDay(System.currentTimeMillis());
longtimeStamp()
time Stamp
return System.currentTimeMillis();