Java Utililty Methods Date Parse

List of utility methods to do Date Parse

Description

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

Method

DateconvertStrToDate(String day)
convert Str To Date
Date parse = dayParse.parse(day);
return parse;
DateconvertStrToDate(String s, String format)
convert Str To Date
SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
try {
    Date date = simpledateformat.parse(s);
    return date;
} catch (Exception exception) {
    exception.printStackTrace();
    Calendar cal = Calendar.getInstance();
    cal.set(1900, 0, 1);
...
DateconvertStrToDate(String source)
convert Str To Date
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(false);
try {
    date = sdf.parse(source);
} catch (ParseException e) {
return date;
...
StringconvertTFormatToCDATime(String tDate)
convert T-format date to CDA format date.
if (tDate == null || tDate.length() < 0)
    return null;
if (tDate.equalsIgnoreCase("T"))
    convertToCDATime(Calendar.getInstance().getTime());
throw new Exception("Need to be implemented!");
StringconvertTimeInMillisecondsToDate(long timeInMilliseconds)
convert Time In Milliseconds To Date
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date(timeInMilliseconds);
return dateFormat.format(date);
StringconvertTimeStampToDate(String dateString, String srcFormat, String destFormat)
This method converts the string timestamp to a date format by trimming of the time entry.
if (srcFormat == null || destFormat == null || srcFormat.isEmpty() || destFormat.isEmpty()) {
    return "";
if (dateString == null || dateString.isEmpty()) {
    return "";
String[] tmpDate = dateString.split(" ");
return changeDateFormat(tmpDate[0], srcFormat, destFormat);
...
StringconvertTimestampToDateTime(Long timestamp, Boolean withSeconds)
convert Timestamp To Date Time
String result = null;
SimpleDateFormat sdf;
if (withSeconds) {
    sdf = new SimpleDateFormat("MM/dd/yyyy(HH:mm:ss.SSS)");
} else {
    sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Date resultdate = new Date(timestamp);
...
DateconvertTimeZonesToDate(String fromTimeZone, String toTimeZone, DateTime fromDateTime)
convert Time Zones To Date
if (fromDateTime == null) {
    return null;
DateTimeZone fromZone = DateTimeZone.forID(fromTimeZone);
DateTimeZone toZone = DateTimeZone.forID(toTimeZone);
DateTime dateTime = new DateTime(fromDateTime);
dateTime = dateTime.withZoneRetainFields(fromZone);
DateTime toDateTime = new DateTime(dateTime).withZone(toZone);
...
StringconvertUTCDateToLocal(String sDate, TimeZone timezone)
Convert the given date following this roles:
  • if the given timezone isn't null, the date is localizated with the timezone and then reformatted in yyyyMMdd'T'HHmmss'Z'.
  • the returned string is always in this format yyyyMMdd'T'HHmmss'Z'
  • if the given timezone is null the date is not changed
if (sDate == null || sDate.equals("") || isInAllDayFormat(sDate)) {
    return sDate;
if (timezone == null) {
    return sDate;
if (!sDate.endsWith("Z")) {
    return sDate;
...
DateconvertXMLDate(String date)
convert XML Date
if (date == null)
    return null;
try {
    return xmlFormat.parse(date);
} catch (ParseException e1) {
    return null;