本文整理汇总了Java中com.ibm.icu.text.DateFormat.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.parse方法的具体用法?Java DateFormat.parse怎么用?Java DateFormat.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toDateWithCheck
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Convert string to date with check.
* JDK may do incorrect converse, for example:
* 2005/1/1 Local.US, format pattern is MM/dd/YY.
* Above conversion can be done without error, but obviously
* the result is not right. This method will do such a simple check,
* in DateFormat.SHORT case instead of all cases.
* Year is not lower than 0.
* Month is from 1 to 12.
* Day is from 1 to 31.
* @param source
* @param locale
* @return Date
* @throws BirtException
*/
public static Date toDateWithCheck( String source, ULocale locale )
throws BirtException
{
DateFormat dateFormat = DateFormatFactory.getDateInstance( DateFormat.SHORT,
locale );
Date resultDate = null;
try
{
resultDate = dateFormat.parse( source );
}
catch ( ParseException e )
{
return toDate( source, locale );
}
// check whether conversion is correct
if ( DateUtil.checkValid( dateFormat, source ) == false )
{
throw new CoreException(
ResourceConstants.CONVERT_FAILS,
new Object[]{
source.toString( ), "Date"
});
}
return resultDate;
}
示例2: processHeader
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Process the header of the file.
* @param config
*
* @param contents Contents of file
* @param content
*/
private void processHeader(Configuration config, List<String> contents, final Map<String, Object> content) {
for (String line : contents) {
if (line.equals(HEADER_SEPARATOR)) {
break;
}
if (line.isEmpty()) {
continue;
}
String[] parts = line.split("=",2);
if (parts.length != 2) {
continue;
}
String key = parts[0].trim();
String value = parts[1].trim();
if (key.equalsIgnoreCase(Crawler.Attributes.DATE)) {
DateFormat df = new SimpleDateFormat(config.getString(Keys.DATE_FORMAT));
Date date = null;
try {
date = df.parse(value);
content.put(key, date);
} catch (ParseException e) {
e.printStackTrace();
}
} else if (key.equalsIgnoreCase(Crawler.Attributes.TAGS)) {
content.put(key, getTags(value));
} else if (isJson(value)) {
content.put(key, JSONValue.parse(value));
} else {
content.put(key, value);
}
}
}
示例3: getDate
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public org.tridas.schema.Date getDate()
{
try {
Date dob=null;
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String enddate = getFieldValueAsString("tridas_sample_samplingdate");
if(enddate==null) return null;
if(enddate.length()<10) return null;
dob = df.parse( enddate.substring(0, 10));
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(dob);
XMLGregorianCalendar xmlDate2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
xmlDate2.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
org.tridas.schema.Date date = new org.tridas.schema.Date();
date.setValue(xmlDate2);
date.setCertainty(Certainty.EXACT);
return date;
} catch (Exception e)
{
log.debug("Error parsing date");
}
return null;
}
示例4: validateInputString
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Validates the locale-dependent value for the date time type, validate the
* <code>value</code> in the locale-dependent way and convert the
* <code>value</code> into a Date object.
*
* @return object of type Date or null if <code>value</code> is null.
*/
public Object validateInputString( Module module, DesignElement element,
PropertyDefn defn, String value ) throws PropertyValueException
{
if ( StringUtil.isBlank( value ) )
{
return null;
}
// Parse the input in locale-dependent way.
ULocale locale = module == null ? ThreadResources.getLocale( ) : module
.getLocale( );
DateFormat formatter = DateFormat.getDateInstance( DateFormat.SHORT,
locale );
try
{
return formatter.parse( value );
}
catch ( ParseException e )
{
logger.log( Level.SEVERE, "Invalid date value:" + value ); //$NON-NLS-1$
throw new PropertyValueException( value,
PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
DATE_TIME_TYPE );
}
}
示例5: toDate
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
public static Date toDate(Object value) throws DataNotCompatibleException {
if (value instanceof Date) {
return (Date) value;
}
if (value == null) {
return null;
}
if (value instanceof Vector && (((Vector<?>) value).isEmpty())) {
return null;
}
if (value instanceof Vector) {
value = ((Vector<?>) value).get(0);
}
if (value instanceof Long) {
return new Date(((Long) value).longValue());
} else if (value instanceof String) {
// TODO finish
DateFormat df = DEFAULT_FORMAT.get();
String str = (String) value;
if (str.length() < 1) {
return null;
}
try {
synchronized (DEFAULT_FORMAT) {
return df.parse(str);
}
} catch (ParseException e) {
throw new DataNotCompatibleException("Cannot create a Date from String value " + (String) value);
}
} else if (value instanceof lotus.domino.DateTime) {
return DominoUtils.toJavaDateSafe((lotus.domino.DateTime) value);
} else if (value instanceof Date) {
return (Date) value;
} else {
throw new DataNotCompatibleException("Cannot create a Date from a " + value.getClass().getName());
}
}
示例6: parseDateFromString
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Parses the date from string.
*
* @param dateString
* the date string
* @return the date
*/
public Date parseDateFromString(final String dateString) {
DateFormat df = getDateTimeFormat();
synchronized (df) {
try {
return df.parse(dateString);
} catch (ParseException e) {
DominoUtils.handleException(e);
return null;
}
}
}
示例7: parseDate
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Parses a string to a date value.
*
* @param val The string to parse.
* @param format The date format.
* @return A date value based on the given string.
* @throws ParseException If val cannot be parsed into a date.
*/
private static DateValue parseDate(String val, DateFormat format)
throws ParseException {
Date date = format.parse(val);
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gc.setTime(date);
return new DateValue(gc);
}
示例8: parseTimeOfDay
import com.ibm.icu.text.DateFormat; //导入方法依赖的package包/类
/**
* Parses a string to a time of day value.
*
* @param val The string to parse.
* @param format The date format.
* @return A time of day value based on the given string.
* @throws ParseException If val cannot be parsed into a date.
*/
private static TimeOfDayValue parseTimeOfDay(String val, DateFormat format)
throws ParseException {
Date date = format.parse(val);
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
gc.setTime(date);
return new TimeOfDayValue(gc);
}