Java Utililty Methods Parse RFC Date

List of utility methods to do Parse RFC Date

Description

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

Method

Dateparse(String rfc1123Date)
parse
try {
    return getDateFormat().parse(rfc1123Date);
} catch (ParseException e) {
    throw new RuntimeException("Failed to parse date from string " + rfc1123Date, e);
DateparseRFC1123(String string)
Parses the given string in RFC1123 format to a Date object.
SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_RFC1123_DATE, Locale.US);
return sdf.parse(string);
DateparseRFC2822Date(String encoded, Date fallback)
parse RFC Date
if (encoded == null)
    return fallback;
try {
    return new MailDateFormat().parse(encoded);
} catch (ParseException e) {
    return fallback;
StringparseRfc2822DateToString(final Date rfcDate)
parse Rfc Date To String
String date = null;
if (rfcDate != null) {
    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT_PARTTERN, Locale.US);
    date = formatter.format(rfcDate);
return date;
CalendarparseRfc3339Calendar(String value)
Parses a datetime+timezone string in one of the following formats, returning a calendar in the given timezone.
SimpleDateFormat sdf = new SimpleDateFormat(RFC3339_DATE_FORMAT);
TimeZone timezone = null;
Date date = null;
if (value.charAt(value.length() - 1) == 'Z') {
    value = value.replace("Z", "GMT-00:00");
    timezone = TimeZone.getTimeZone("GMT-00:00");
    date = sdf.parse(value);
} else if (value.indexOf("GMT") == -1
...
DateparseRfc3339Date(String date)
Parses a datetime+timezone string in one of the following formats, returning a UTC date: 2002-10-10T00:00:00+05:00 2002-10-10T00:00:00GMT+05:00
return parseDate(date, RFC3339_DATE_FORMAT);
DateparseRFC3339Date(String datestring)
To deal with RFC3339 Date
Date d = new Date();
if (datestring.endsWith("Z")) {
    SimpleDateFormat s = new SimpleDateFormat(RFC3399_DATE_FORMAT);
    s.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
        d = s.parse(datestring);
    } catch (java.text.ParseException pe) {
        s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
...
DateparseRFC3339Date(String datestring)
parse RFC Date
Date d = new Date();
if (datestring.endsWith("Z")) {
    try {
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        d = s.parse(datestring);
    } catch (java.text.ParseException pe) {
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
        s.setLenient(true);
...
DateparseRFC822(String dateString)
parse RFC
return rfc822DateFormat.parse(dateString);
DateparseRFC822(String sDate, Locale locale)
parse RFC
int utIndex = sDate.indexOf(" UT");
if (utIndex > -1) {
    String pre = sDate.substring(0, utIndex);
    String post = sDate.substring(utIndex + 3);
    sDate = pre + " GMT" + post;
return parseUsingMask(RFC822_MASKS, sDate, locale);