Java Utililty Methods Timestamp Convert To

List of utility methods to do Timestamp Convert To

Description

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

Method

DateconvertDate(Timestamp time)
convert Date
return time == null ? null : new Date(time.getTime());
TimestampConvertTimestamp(long sec)
Convert Timestamp
long unixSeconds = sec / 1000;
Date date = new Date(unixSeconds * 1000L); 
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); 
String dt = sdf.format(date);
return Timestamp.valueOf(dt);
CalendarconvertTimestamp(Timestamp timestamp)
convert Timestamp
if (timestamp == null) {
    return null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(timestamp);
return calendar;
DateconvertTimestampToDate(Timestamp timestamp)
convert Timestamp To Date
Date date = timestamp;
return date;
StringconvertTimestampToDDMMMMYYYY(Timestamp dateTime)
convert timestamp to format dd MMMM yyyy
String s = "";
java.text.SimpleDateFormat ft = null;
ft = new java.text.SimpleDateFormat("dd MMMM yyyy");
s = ft.format(dateTime);
if (s.indexOf("Jan") > -1) {
    s = s.replace("January", "Januari");
} else if (s.indexOf("Feb") > -1) {
    s = s.replace("February", "Februari");
...
StringconvertTimestampToString(Timestamp dateTime, String dateFormat)
convert timestamp to format yyyyMMdd
String s = "";
java.text.SimpleDateFormat ft = null;
ft = new java.text.SimpleDateFormat(dateFormat);
s = ft.format(dateTime);
return s;
StringconvertTimestampToString(Timestamp str)
convert Timestamp To String
return convertTimestampToString(str, "yyyy-MM-dd HH:mm:ss");
StringconvertTimestampToStringWithoutTime(final Timestamp ts)
convert Timestamp To String Without Time
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(ts.getTime());
return cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DAY_OF_MONTH);
DateconvertToDate(Timestamp aTimeStamp)
convert To Date
Date res = null;
if (aTimeStamp != null) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(new Date(aTimeStamp.getTime()));
    res = calendar.getTime();
return res;
java.util.DateconvertToDate(Timestamp timestamp)
convert To Date
return new java.util.Date(timestamp.getTime());