Android Utililty Methods Date String Parse

List of utility methods to do Date String Parse

Description

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

Method

StringparseIcalDateToString(Date date, TimeZone tz)
Pase the Ical Date to a String
StringBuilder sb = new StringBuilder();
SimpleDateFormat timeFormat = new SimpleDateFormat("HHmm",
        Locale.getDefault());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd",
        Locale.getDefault());
if (tz != null) {
    timeFormat.setTimeZone(tz);
    dateFormat.setTimeZone(tz);
...
StringparseDate(String s)
parse Date
SimpleDateFormat inputFormat = new SimpleDateFormat("MMM dd, yyyy");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
    return outputFormat.format(inputFormat.parse(s));
} catch (ParseException e) {
    return "";
DateparseDate(String value)
Loops over all the possible date formats and tries to find the right one.
if (value == null) {
    return null;
Date date = null;
for (ThreadLocal<SimpleDateFormat> format : DATETIME_FORMATS) {
    try {
        date = format.get().parse(value);
        break;
...
DateparseLastfmDate(String date)
parse Lastfm Date
if (date == null) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date playlistDate = null;
try {
...
DateparseLastfmDateAlbum(String date)
parse Lastfm Date Album
if (date == null) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "dd MMMM yyyy, HH:mm");
Date parsedDate = null;
try {
    parsedDate = dateFormat.parse(date);
...
DateparseLastfmDateLong(String date)
parse Lastfm Date Long
if (date == null) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "EEE, dd MMMM yyyy HH:mm:ss ZZZZ");
Date parsedDate = null;
try {
    parsedDate = dateFormat.parse(date);
...
booleanisDate(String date)
is Date
String format = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(date);
return matcher.matches();