Code example for Scanner

Methods: hasNext, nextInt

0
	 * @return An object representation of the given Date and Time string 
	 */ 
	private static GregorianCalendar parseXMLDateTime(String xmlDateTime) {
		String dateTimeString = xmlDateTime.replace('-', ' ').replace('T', ' ')
				.replace('Z', ' ').replace(':', ' ');
		Scanner s = new Scanner(dateTimeString);
 
		try { 
			int year = s.nextInt();
			int month = s.nextInt() - 1; //String from xml is 1-based
			int day = s.nextInt();
 
			// Return if only the date is included 
			if (!s.hasNext())
				return new GregorianCalendar(year, month, day);
			int hour = s.nextInt();
			int minute = s.nextInt();
			int second = s.nextInt();
 
			return new GregorianCalendar(year, month, day, hour, minute, second);
		} catch (IllegalStateException e) {
			return null; 
		} catch (NoSuchElementException e) {