Java Utililty Methods Timestamp Parse

List of utility methods to do Timestamp Parse

Description

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

Method

CalendarparseTimestamp(String timestamp, String dateFormat, Locale locale)
parse Timestamp
if (locale == null) {
    locale = Locale.getDefault();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, locale);
Date d = sdf.parse(timestamp);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
return cal;
...
TimestampparseTimeStamp(String timeStampString)
parse timestamp.
Timestamp result = null;
try {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    Date parsed = format.parse(timeStampString);
    result = new Timestamp(parsed.getTime());
} catch (ParseException pe) {
    System.out.println("ERROR: Cannot parse \"" + timeStampString + "\"");
} catch (Exception x) {
...
TimestampparseTimestamp(String value)
Parse the date of the form, "yyyy-MM-dd HH:mm:ss.N".
try {
    return new Timestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.N").parse(value).getTime());
} catch (Exception exception) {
    try {
        return new Timestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value).getTime());
    } catch (Exception exception2) {
        return null;
DateparseTimestamp(String value)
Parse UNIX timestamp as it is returned by the
final String pattern = "yyyyMMdd.HHmmss";
if (value != null && value.length() >= pattern.length()) {
    try {
        return new SimpleDateFormat(pattern).parse(value);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
} else {
...
longparseTimestamp2Long(String datestring, String datepattern, TimeZone timeZone)
parse date string with a given date pattern, return long type timestamp, unit:second precondition: it is better to call cubridmanager.CommonTool.validateTimestamp(String, String) first to void throwing an ParseException
DateFormat formatter = getDateFormat(datepattern, Locale.US, timeZone);
Date date = formatter.parse(datestring);
return date.getTime();
DateparseTimestampDirectory(final String stamp)
parse Timestamp Directory
final DateFormat format;
if (stamp.length() == 18) {
    format = new SimpleDateFormat(TSDIR_MILLISECONDS_FORMAT);
} else {
    format = new SimpleDateFormat(TSDIR_SECONDS_FORMAT);
return format.parse(stamp);
StringparseTimestampToString(Timestamp stamp, String dateFormat)
parse Timestamp To String
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(new Date(stamp.getTime()));
DateparseToDate(String timestamp, String pattern)
Parses the to date.
Date date = null;
try {
    date = new SimpleDateFormat(pattern, Locale.ENGLISH).parse(timestamp);
} catch (ParseException e) {
    e.printStackTrace();
return date;
Timestampstr2Timestamp(String str)
str Timestamp
Date date = str2Date(str, date_sdf);
return new Timestamp(date.getTime());
java.sql.TimestampString2Timestamp(String date)
String Timestamp
Integer year = new Integer(date.substring(0, 4));
Integer month = new Integer(date.substring(5, 7));
Integer dan = new Integer(date.substring(8, 10));
Calendar cal = Calendar.getInstance();
cal.set(year.intValue(), month.intValue() + 1, dan.intValue(), 0, 0, 0);
return new java.sql.Timestamp(cal.getTime().getTime());