Search in sources :

Example 86 with ParsePosition

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

the class DateUtilsBasic method getEDate.

/**
	 * 返回美国时间格式 26 Apr 2006.
	 * @param str
	 *            	时间字符串
	 * @return String
	 * 				如果传入的字符串为 2011-06-23,则返回 23JUN11
	 */
public static String getEDate(String str) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    ParsePosition pos = new ParsePosition(0);
    Date strtodate = formatter.parse(str, pos);
    String j = strtodate.toString();
    String[] k = j.split(" ");
    return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 87 with ParsePosition

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

the class DateUtilsBasic method strToDate.

/**
	 * 将时间字符串按指定格式转换为日期
	 * @param strDate
	 *            时间字符串
	 * @param format
	 *            日期格式
	 * @return Date
	 * 			  返回按指定格式得到的时间, 如果 strDate 为 null,返回 null
	 */
public static Date strToDate(String strDate, String format) {
    if (strDate == null) {
        return null;
    }
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    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)

Example 88 with ParsePosition

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

the class Wf2Xliff method getR8dateStrFromUTC.

/**
	 * 转换时间
	 * @param strDate
	 * @return
	 */
private static String getR8dateStrFromUTC(String _UTCDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
    ParsePosition pos = new ParsePosition(0);
    Date str2Date = formatter.parse(_UTCDate, pos);
    SimpleDateFormat formatter_1 = new SimpleDateFormat("yyyy-MM-dd");
    return formatter_1.format(str2Date);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 89 with ParsePosition

use of java.text.ParsePosition in project react-native-image-picker by marcshilling.

the class ImagePickerModule method parseTimestamp.

/**
   * Returns number of milliseconds since Jan. 1, 1970, midnight local time.
   * Returns -1 if the date time information if not available.
   * copied from ExifInterface.java
   * @hide
   */
private static long parseTimestamp(String dateTimeString, String subSecs) {
    if (dateTimeString == null)
        return -1;
    SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.getDefault());
    sFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    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();
        if (subSecs != null) {
            try {
                long sub = Long.valueOf(subSecs);
                while (sub > 1000) {
                    sub /= 10;
                }
                msecs += sub;
            } catch (NumberFormatException e) {
            //expected
            }
        }
        return msecs;
    } catch (IllegalArgumentException ex) {
        return -1;
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 90 with ParsePosition

use of java.text.ParsePosition in project okhttp by square.

the class HttpDate method parse.

/** Returns the date for {@code value}. Returns null if the value couldn't be parsed. */
public static Date parse(String value) {
    if (value.length() == 0) {
        return null;
    }
    ParsePosition position = new ParsePosition(0);
    Date result = STANDARD_DATE_FORMAT.get().parse(value, position);
    if (position.getIndex() == value.length()) {
        // non-standard trailing "+01:00". Those cases are covered below.
        return result;
    }
    synchronized (BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS) {
        for (int i = 0, count = BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.length; i < count; i++) {
            DateFormat format = BROWSER_COMPATIBLE_DATE_FORMATS[i];
            if (format == null) {
                format = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
                // Set the timezone to use when interpreting formats that don't have a timezone. GMT is
                // specified by RFC 2616.
                format.setTimeZone(UTC);
                BROWSER_COMPATIBLE_DATE_FORMATS[i] = format;
            }
            position.setIndex(0);
            result = format.parse(value, position);
            if (position.getIndex() != 0) {
                // trailing junk is ignored.
                return result;
            }
        }
    }
    return null;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) 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