Search in sources :

Example 96 with ParsePosition

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

the class DateUtils method strToDate.

/**
	 * 将短时间格式字符串转换为时间 yyyy-MM-dd
	 * @param strDate
	 * @return
	 */
public static Date strToDate(String strDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    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 97 with ParsePosition

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

the class SourceTargetComparer method main.

public static void main(String[] args) {
    // String str1 = "11wfw21dwq33dqwaa44";
    // String str2 = "11 bbwd22qwds21gre33";
    // System.out.println(replaceNumber(str1, str2));
    /** Part.1 使用正则表达式 **/
    // String regx = "\\d{4}\\-\\d{1,2}\\-\\d{1,2}\\s\\d{1,2}\\:\\d{1,2}\\:\\d{1,2}";
    // Pattern p = Pattern.compile(regx);
    // Matcher m = p.matcher("你好 - 2008-8-7 12:04:11 - 中国2010-11-11 11:52:30 dwqdqw");
    // while (m.find()) {
    // System.out.println(m.group());
    // }
    /** Part.2 使用 java.text.SimpleDateFormat.parse(String text, ParsePosition pos) 方法 **/
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str = "form:   2008-8-7 12:04:11  to  2010-11-11 11:52:30, over!";
    ParsePosition pos;
    for (int i = 0; i < str.length(); ) {
        pos = new ParsePosition(i);
        int start = i;
        Date date = sdf.parse(str, pos);
        if (date != null) {
            i = pos.getIndex();
            System.out.println(str.substring(start, i).trim());
        } else {
            i++;
        }
    }
/** Part.3 使用“()”为正则表达式添加分组 **/
// Pattern p=Pattern.compile("(\\d{4})-(\\d{1,2})-(\\d{1,2})");
// Matcher m=p.matcher("x20xxx1984-10-20xxx19852x");
//				     
// if(m.find()){
// System.out.println("日期:"+m.group());
// System.out.println("年:"+m.group(1));
// System.out.println("月:"+m.group(2));
// System.out.println("日:"+m.group(3));
// }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 98 with ParsePosition

use of java.text.ParsePosition in project realm-java by realm.

the class ISO8601UtilsTest method testFractionalSeconds.

public void testFractionalSeconds() throws java.text.ParseException {
    Date d = ISO8601Utils.parse("1970-01-01T00:00:00.9Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 900, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.09Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 90, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.009Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 9, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.0009Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 0, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.2147483647Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 214, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.2147483648Z", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 214, 0), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.9+02:00", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 900, 2 * 60), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.09+02:00", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 90, 2 * 60), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.009+02:00", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 9, 2 * 60), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.0009+02:00", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 0, 2 * 60), d);
    d = ISO8601Utils.parse("1970-01-01T00:00:00.2147483648+02:00", new ParsePosition(0));
    assertEquals(newDate(1970, 1, 1, 0, 0, 0, 214, 2 * 60), d);
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 99 with ParsePosition

use of java.text.ParsePosition in project realm-java by realm.

the class ISO8601UtilsTest method testParse.

public void testParse() throws java.text.ParseException {
    Date d = ISO8601Utils.parse("2007-08-13T19:51:23.789Z", new ParsePosition(0));
    assertEquals(date, d);
    d = ISO8601Utils.parse("2007-08-13T19:51:23Z", new ParsePosition(0));
    assertEquals(dateZeroMillis, d);
    d = ISO8601Utils.parse("2007-08-13T21:51:23.789+02:00", new ParsePosition(0));
    assertEquals(date, d);
}
Also used : Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 100 with ParsePosition

use of java.text.ParsePosition in project realm-java by realm.

the class ISO8601UtilsTest method testParseShortDate.

public void testParseShortDate() throws java.text.ParseException {
    Date d = ISO8601Utils.parse("20070813T19:51:23.789Z", new ParsePosition(0));
    assertEquals(date, d);
    d = ISO8601Utils.parse("20070813T19:51:23Z", new ParsePosition(0));
    assertEquals(dateZeroMillis, d);
    d = ISO8601Utils.parse("20070813T21:51:23.789+02:00", new ParsePosition(0));
    assertEquals(date, d);
}
Also used : 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