Java Utililty Methods Date to Timestamp

List of utility methods to do Date to Timestamp

Description

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

Method

StringtimeStamp(Date date)
Creates a formatted timestamp string of the given date using the local host timezone.
return timeStamp(date, null);
Stringtimestamp(Date dateAndTime)
Return a string holding the time and date in the form:
 Thursday, May 29, 2003 11:42:44 AM 
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM).format(dateAndTime);
StringtimestampSec(Date date)
timestamp Sec
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
return dateFormat.format(date);
StringTimestampToString(Date thisdate)
Timestamp To String
if (thisdate != null) {
    SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance();
    sdf.applyPattern("yyyy-MM-dd HH:mm:sss");
    return sdf.format(thisdate);
} else {
    return "";
DatetoDate(String timeStamp)
to Date
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'SSS");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.parse(timeStamp);
} catch (ParseException e) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
...
StringtoDateStringFromResources(String timestamp)
Convert timestamp string into a localised date string
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
Date d = null;
try {
    d = format.parse(timestamp);
} catch (ParseException e) {
    e.printStackTrace();
DateFormat formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
...
StringtoDateTime(String timeStamp)
to Date Time
try {
    Long ts = Long.parseLong(timeStamp) * 1000;
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sdf.format(new java.util.Date(ts));
} catch (NumberFormatException e) {
    return "";
DateunixTimestampToDate(int timestamp)
unix Timestamp To Date
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp * 1000l);
return calendar.getTime();