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

java.sql.TimestampgetTimestamp(String strDate)
Converts a String date in a "jj/mm/aaaa" format in a java.sql.Timestamp type date
ParsePosition pos = new ParsePosition(0);
java.util.Date date = _formatter.parse(strDate, pos);
if (date != null) {
    return (new java.sql.Timestamp(date.getTime()));
return null;
TimestampgetTimestamp(String time, String pattern)
get Timestamp
DateFormat format = new SimpleDateFormat(pattern);
format.setLenient(false);
Timestamp ts = null;
try {
    ts = new Timestamp(format.parse(time).getTime());
} catch (ParseException e) {
    e.printStackTrace();
return ts;
TimestampgetTimestamp2()
get Timestamp
Date dt = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTime = df.format(dt);
java.sql.Timestamp buydate = java.sql.Timestamp.valueOf(nowTime);
return buydate;
StringgetTimeStampAsString(Timestamp formatTime)
get Time Stamp As String
SimpleDateFormat m_format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return m_format.format(formatTime);
StringgetTimestampAsString(Timestamp tsTimestamp)
Convert timestamp to string including it's nanosecond portion so that it can be safely stored in variable of web page.
StringBuilder sbTimestamp = new StringBuilder();
sbTimestamp.append(tsTimestamp.getTime());
sbTimestamp.append(NANO_SEPARATOR);
sbTimestamp.append(tsTimestamp.getNanos());
return sbTimestamp.toString();
TimestampgetTimestampAtMidnightForDaysAgo(int days)
get Timestamp At Midnight For Days Ago
Calendar now = new GregorianCalendar();
now.add(Calendar.DAY_OF_YEAR, -days);
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
return new Timestamp(now.getTimeInMillis());
TimestampgetTimestampBeforeMs(long someMs)
get Timestamp Before Ms
return new Timestamp(System.currentTimeMillis() - someMs);
StringgetTimeStampByFormat(String style)
get Time Stamp By Format
DateFormat format = new SimpleDateFormat(style);
return format.format(new Date());
StringgetTimestampDate(long timestamp)
get Timestamp Date
return formatDate("dd.MM.yyyy", timestamp);
StringgetTimestampDate(Timestamp ts)
get Timestamp Date
Calendar c = Calendar.getInstance();
c.setTimeInMillis(ts.getTime());
return formatNumber("00", c.get(Calendar.MONTH) + 1) + "/"
        + formatNumber("00", c.get(Calendar.DAY_OF_MONTH)) + "/"
        + formatNumber("00", c.get(Calendar.YEAR) % 100);