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

TimestampgetTimestampFromDateTime(DateTime dateTime)
get Timestamp From Date Time
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Timestamp timestamp = null;
if (dateTime != null) {
    timestamp = new Timestamp(dateTime.getMillis());
return timestamp;
TimestampgetTimeStampFromISOString(String isoString)
get Time Stamp From ISO String
Timestamp result;
try {
    Calendar caldate = Calendar.getInstance();
    int year = 0;
    int month = 0;
    int day = 0;
    int hour = 0;
    int min = 0;
...
java.sql.TimestampgetTimestampFromString(String dateStr)
get Timestamp From String
if (dateStr == null || dateStr.equals("")) {
    return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(dateStr, pos);
if (strtodate == null) {
    strtodate = new Date();
...
TimestampgetTimestampFromString(String dateString, String dateFormat)
Trasform a date string into a timestamp
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
Date parsedDate = format.parse(dateString);
Timestamp ts = new Timestamp(parsedDate.getTime());
return ts;
longgetTimestampFromString(String id)
get Timestamp From String
String a[] = id.split("-");
return new SimpleDateFormat("yyyyMMddHHmmss").parse(a[1]).getTime() / 1000;
TimestampgetTimestampFromString(String s)
get Timestamp From String
Timestamp result;
s = s.trim();
int periodIdx = s.indexOf(".");
if (periodIdx != -1) {
    if (s.length() - periodIdx > 9) {
        s = s.substring(0, periodIdx + 10);
try {
    result = Timestamp.valueOf(s);
} catch (IllegalArgumentException e) {
    result = null;
return result;
TimestampgetTimeStampFromString(String timeStamp)
get Time Stamp From String
return Timestamp.valueOf(timeStamp);
StringgetTimestampInEnglish(java.sql.Timestamp t)
get Timestamp In English
if (t == null)
    return "";
String s = t.toString();
if (s.indexOf(".0") > 0)
    s = s.substring(0, s.indexOf(".0"));
String[] sr = s.split(" ");
int month = -1;
int day = -1;
...
StringgetTimestampLexical(boolean showSeconds, Locale locale)
Gets timestamp lexical.
if (showSeconds)
    return new SimpleDateFormat("yyyyMMddhhmmss", locale).format(new Date());
else
    return new SimpleDateFormat("yyyyMMddhhmm", locale).format(new Date());
TimestampgetTimestampMinusDays(Integer days)
Return a sql timestamp minus for the current day minus the specified days
Date d = getDateMinusDays(days);
if (d != null) {
    return new Timestamp(d.getTime());
return null;