Search in sources :

Example 6 with ParsePosition

use of java.text.ParsePosition in project OpenAM by OpenRock.

the class Locale method parseDateString.

/**
     * Gets Date object from date string with specified locale.
     * 
     * @param dateString
     *            date string
     * @param locale
     *            Locale object
     * @param dateSyntax
     *            syntax of the date string.
     * 
     * @return Date object returned if <code>dateString</code> matches the
     *         <code> dateSyntax</code>. If the syntax or date string is
     *         empty, or the string does not match the syntax, null will be
     *         returned.
     */
public static Date parseDateString(String dateString, java.util.Locale locale, String dateSyntax) {
    if (debug.messageEnabled()) {
        debug.message("Local.parseDateString(date, locale, syntax)");
        debug.message("date string = " + dateString);
        debug.message("date syntax = " + dateSyntax);
        debug.message("locale = " + locale.toString());
    }
    if ((dateString == null) || (dateString.length() < 1) || (dateSyntax == null) || (dateSyntax.length() < 1)) {
        return null;
    }
    SimpleDateFormat sdf = new SimpleDateFormat(dateSyntax);
    sdf.setLenient(false);
    ParsePosition pos = new ParsePosition(0);
    Date date = sdf.parse(dateString, pos);
    if (date == null) {
        debug.warning("Locale.parseDateString: unable to parse the date.");
    }
    return date;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 7 with ParsePosition

use of java.text.ParsePosition in project tdi-studio-se by Talend.

the class BusinessAbstractParser method isValidEditString.

/**
     * @generated NOT
     */
public IParserEditStatus isValidEditString(IAdaptable element, String editString) {
    ParsePosition pos = new ParsePosition(0);
    Object[] values = getEditProcessor().parse(editString, pos);
    if (values == null) {
        return new ParserEditStatus(BusinessDiagramEditorPlugin.ID, IParserEditStatus.UNEDITABLE, Messages.getString(//$NON-NLS-1$
        "BusinessAbstractParser.InvalidInputAt") + pos.getErrorIndex());
    }
    return validateNewValues(values);
}
Also used : ParserEditStatus(org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus) IParserEditStatus(org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus) EObject(org.eclipse.emf.ecore.EObject) ParsePosition(java.text.ParsePosition)

Example 8 with ParsePosition

use of java.text.ParsePosition in project android_frameworks_base by ResurrectionRemix.

the class ExifInterface method getGpsDateTime.

/**
     * Returns number of milliseconds since Jan. 1, 1970, midnight UTC.
     * Returns -1 if the date time information if not available.
     * @hide
     */
public long getGpsDateTime() {
    String date = getAttribute(TAG_GPS_DATESTAMP);
    String time = getAttribute(TAG_GPS_TIMESTAMP);
    if (date == null || time == null || (!sNonZeroTimePattern.matcher(date).matches() && !sNonZeroTimePattern.matcher(time).matches())) {
        return -1;
    }
    String dateTimeString = date + ' ' + time;
    ParsePosition pos = new ParsePosition(0);
    try {
        Date datetime = sFormatter.parse(dateTimeString, pos);
        if (datetime == null)
            return -1;
        return datetime.getTime();
    } catch (IllegalArgumentException e) {
        return -1;
    }
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 9 with ParsePosition

use of java.text.ParsePosition in project jackson-databind by FasterXML.

the class ISO8601UtilsTest method testParseShortDateTime.

public void testParseShortDateTime() throws java.text.ParseException {
    Date d = ISO8601Utils.parse("20070813T195123.789Z", new ParsePosition(0));
    assertEquals(date, d);
    d = ISO8601Utils.parse("20070813T195123Z", new ParsePosition(0));
    assertEquals(dateZeroMillis, d);
    d = ISO8601Utils.parse("20070813T215123.789+02:00", new ParsePosition(0));
    assertEquals(date, d);
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 10 with ParsePosition

use of java.text.ParsePosition in project jackson-databind by FasterXML.

the class ISO8601UtilsTest method testParseWithoutTime.

public void testParseWithoutTime() throws ParseException {
    Date d = ISO8601Utils.parse("2007-08-13Z", new ParsePosition(0));
    assertEquals(dateWithoutTime, d);
    d = ISO8601Utils.parse("20070813Z", new ParsePosition(0));
    assertEquals(dateWithoutTime, d);
    d = ISO8601Utils.parse("2007-08-13+00:00", new ParsePosition(0));
    assertEquals(dateWithoutTime, d);
    d = ISO8601Utils.parse("20070813+00:00", new ParsePosition(0));
    assertEquals(dateWithoutTime, d);
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Aggregations

ParsePosition (java.text.ParsePosition)704 Test (org.junit.Test)253 Date (java.util.Date)221 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)125 DateTimeFormatter (java.time.format.DateTimeFormatter)94 Test (org.testng.annotations.Test)88 ParseException (java.text.ParseException)71 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)49 SimpleDateFormat (android.icu.text.SimpleDateFormat)39 FieldPosition (java.text.FieldPosition)32 Calendar (java.util.Calendar)26 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17