Java Utililty Methods String to Timestamp

List of utility methods to do String to Timestamp

Description

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

Method

StringcalculateClientRequestId(String timestamp)
This method is used to calculate the clientRequestId parameter of a request.
try {
    return String.valueOf(sdf.parse(timestamp).getTime());
} catch (ParseException e) {
    return "-1";
StringgetFileNameWithTimeStampInterposed(final String fileName)
Interpose a time stamp between the file name and extension
String namePart = getFileNameUpToExtension(fileName);
String extension = getFileExtension(fileName);
StringBuilder newName = new StringBuilder(namePart);
newName.append(".[backup from - ");
DateFormat dateFormat = DateFormat.getDateTimeInstance();
newName.append(dateFormat.format(new Date()));
newName.append("]");
newName.append(extension);
...
longgetStringToTimestamp(String string)
return unix timestamp of specified string value in format: yyyy-MM-dd HH:mm:ss
try {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ParsePosition parsePosition = new ParsePosition(0);
    Date date = simpleDateFormat.parse(string, parsePosition);
    return date.getTime();
} catch (Exception e) {
    return -1;
StringgetTimeStamp(String date)
get Time Stamp
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
ParsePosition pos = new ParsePosition(0);
Date d = formatter.parse(date, pos);
return String.valueOf(d.getTime());
StringgetTimeStamp(String dateTime)
get Time Stamp
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd hh:mm:ss");
Date date = null;
try {
    date = sdf.parse(dateTime);
} catch (ParseException e) {
    e.printStackTrace();
Calendar calendar = Calendar.getInstance();
...
longgetTimestamp(String dateValue, String pattern, TimeZone timezone)
get Timestamp
DateFormat d = new SimpleDateFormat(pattern);
Calendar c = Calendar.getInstance(timezone);
c.setTime(d.parse(dateValue));
return c.getTimeInMillis();
StringgetTimestamp(String pattern)
get Timestamp
return getTime(new Date(), pattern, currentLocale);
longgetTimeStamp(String pattern, String strDate)
get Time Stamp
long returnTimeStamp = 0;
Date aDate = null;
try {
    aDate = convertStringToDate(pattern, strDate);
} catch (ParseException pe) {
    aDate = null;
if (aDate == null) {
...
StringgetTimeStamp(String style, Date date)
get Time Stamp
DateFormat format = new SimpleDateFormat(style);
return format.format(date);
StringgetTimestamp(String timeStampStr, String logRundateIdStr)
get Timestamp
SimpleDateFormat timeDf = new SimpleDateFormat("yyyyMMdd");
String resultValue = "0";
try {
    new Date(Long.valueOf(timeStampStr) * 1000);
    resultValue = timeStampStr;
} catch (NumberFormatException e) {
    try {
        Date date = timeDf.parse(logRundateIdStr);
...