Search in sources :

Example 81 with ParsePosition

use of java.text.ParsePosition in project robovm by robovm.

the class SimpleDateFormatTest method parseDate.

private static Calendar parseDate(Locale l, String fmt, String value) {
    SimpleDateFormat sdf = new SimpleDateFormat(fmt, l);
    ParsePosition pp = new ParsePosition(0);
    Date d = sdf.parse(value, pp);
    if (d == null) {
        fail(pp.toString());
    }
    Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    c.setTime(d);
    return c;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 82 with ParsePosition

use of java.text.ParsePosition in project robovm by robovm.

the class OldSimpleDateFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition_2.

public void test_parseLjava_lang_StringLjava_text_ParsePosition_2() {
    try {
        format.parse("240 11 2002 March", null);
        fail("ParsePosition is null: NullPointerException was not thrown.");
    } catch (NullPointerException pe) {
    //expected
    }
    try {
        format.parse(null, new ParsePosition(0));
        fail("String is null: NullPointerException was not thrown.");
    } catch (NullPointerException pe) {
    //expected
    }
}
Also used : ParsePosition(java.text.ParsePosition)

Example 83 with ParsePosition

use of java.text.ParsePosition in project platform_frameworks_base by android.

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 84 with ParsePosition

use of java.text.ParsePosition in project platform_frameworks_base by android.

the class ExifInterface method getDateTime.

/**
     * Returns number of milliseconds since Jan. 1, 1970, midnight local time.
     * Returns -1 if the date time information if not available.
     * @hide
     */
public long getDateTime() {
    String dateTimeString = getAttribute(TAG_DATETIME);
    if (dateTimeString == null || !sNonZeroTimePattern.matcher(dateTimeString).matches())
        return -1;
    ParsePosition pos = new ParsePosition(0);
    try {
        // The exif field is in local time. Parsing it as if it is UTC will yield time
        // since 1/1/1970 local time
        Date datetime = sFormatter.parse(dateTimeString, pos);
        if (datetime == null)
            return -1;
        long msecs = datetime.getTime();
        String subSecs = getAttribute(TAG_SUBSEC_TIME);
        if (subSecs != null) {
            try {
                long sub = Long.parseLong(subSecs);
                while (sub > 1000) {
                    sub /= 10;
                }
                msecs += sub;
            } catch (NumberFormatException e) {
            // Ignored
            }
        }
        return msecs;
    } catch (IllegalArgumentException e) {
        return -1;
    }
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 85 with ParsePosition

use of java.text.ParsePosition in project translationstudio8 by heartsome.

the class DateUtilsBasic method strToDateLong.

/**
	 * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss.
	 * @param strDate
	 *            	指定的日期字符串
	 * @return Date
	 * 				返回时间类型 yyyy-MM-dd HH:mm:ss
	 */
public static Date strToDateLong(String strDate) {
    if (strDate == null) {
        return null;
    }
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ParsePosition pos = new ParsePosition(0);
    Date strtodate = formatter.parse(strDate, pos);
    return strtodate;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Aggregations

ParsePosition (java.text.ParsePosition)694 Test (org.junit.Test)250 Date (java.util.Date)213 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)117 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 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Calendar (java.util.Calendar)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17