Here you can find the source of asDate(final String literal)
Parameter | Description |
---|---|
literal | the string literal |
Parameter | Description |
---|---|
ParseException | thrown if literal cannot be format as date |
public static final Calendar asDate(final String literal) throws ParseException
//package com.java2s; /*/*from w ww .j a v a2s . c o m*/ * Copyright: Copyright 2010 Topic Maps Lab, University of Leipzig. http://www.topicmapslab.de/ * License: Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html * * @author Sven Krosse * @email krosse@informatik.uni-leipzig.de * */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.List; public class Main { /** * translation patterns of date */ private static final List<String> datePatterns = new LinkedList<String>(); /** * Method formats the given literal as date literal. * * @param literal * the string literal * @return the date literal * @throws ParseException * thrown if literal cannot be format as date */ public static final Calendar asDate(final String literal) throws ParseException { Date date = null; for (String pattern : datePatterns) { try { date = new SimpleDateFormat(pattern).parse(literal); } catch (ParseException e) { // VOID } } if (date == null) { throw new ParseException("Invalid date pattern", -1); } Calendar c = new GregorianCalendar(); c.setTime(date); return c; } }