当前位置: 首页>>代码示例>>Java>>正文


Java DateFormat.parse方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:43,代码来源:DataTypeUtil.java

示例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);
        }
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:44,代码来源:MarkupEngine.java

示例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;
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:33,代码来源:ODKParser.java

示例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 );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:34,代码来源:DateTimePropertyType.java

示例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());
	}
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:38,代码来源:TypeUtils.java

示例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;
		}
	}
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:19,代码来源:DominoFormatter.java

示例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);
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:16,代码来源:GVizTypeConverter.java

示例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);
}
 
开发者ID:jyang,项目名称:google-feedserver,代码行数:16,代码来源:GVizTypeConverter.java


注:本文中的com.ibm.icu.text.DateFormat.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。