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;
}
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));
// }
}
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);
}
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);
}
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);
}
Aggregations