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