Here you can find the source of parseDate(String atomPubDate, Locale locale)
Parameter | Description |
---|---|
atomPubDate | a parameter |
public static Date parseDate(String atomPubDate, Locale locale)
/******************************************************************************* * Copyright (C) 2005-2012 Alfresco Software Limited. * //from ww w .j a v a 2s . c o m * This file is part of the Alfresco Mobile SDK. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class Main{ private static final String[] DATE_FORMATS = { FORMAT_1, FORMAT_2, FORMAT_3, FORMAT_4, FORMAT_5 }; public static Date parseDate(String atomPubDate) { return parseDate(atomPubDate, Locale.getDefault()); } /** * @since 1.0.1 * @param atomPubDate * @return */ public static Date parseDate(String atomPubDate, Locale locale) { Date d = null; SimpleDateFormat sdf; for (int i = 0; i < DATE_FORMATS.length; i++) { sdf = new SimpleDateFormat(DATE_FORMATS[i], locale); sdf.setLenient(true); try { d = sdf.parse(atomPubDate); break; } catch (ParseException e) { continue; } } if (d == null) { for (int i = 0; i < DATE_FORMATS.length; i++) { sdf = new SimpleDateFormat(DATE_FORMATS[i], Locale.ENGLISH); sdf.setLenient(true); try { d = sdf.parse(atomPubDate); break; } catch (ParseException e) { continue; } } } return d; } public static Date parseDate(String date, String format) { if (date == null) { return null; } return parseDate(date, new SimpleDateFormat(format, Locale.getDefault())); } /** * @since 1.0.1 * @param atomPubDate * @return */ public static Date parseDate(String date, SimpleDateFormat sdf) { Date d = null; sdf.setLenient(true); try { d = sdf.parse(date); } catch (ParseException e) { d = parseDate(date); } return d; } }