Here you can find the source of getYearFromISODate(String isoDate)
Parameter | Description |
---|---|
isoDate | a parameter |
public static Integer getYearFromISODate(String isoDate)
//package com.java2s; /**//w ww.ja va2 s.c o m * Archivists' Toolkit(TM) Copyright 2005-2007 Regents of the University of California, New York University, & Five Colleges, Inc. * All rights reserved. * * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL) * version 1.0 (http://www.opensource.org/licenses/ecl1.php) * * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations. * * * Archivists' Toolkit(TM) * http://www.archiviststoolkit.org * info@archiviststoolkit.org * * * Simple utility class for checking that an entered date is valid for the given database * and for handeling iso dates in the AT * * Created by IntelliJ IDEA. * User: Nathan Stevens * Date: Aug 28, 2008 * Time: 10:46:58 AM * To change this template use File | Settings | File Templates. */ public class Main { /** * Method to return the year part from an iso date in either * yyyy, yyyy-mm, or yyyy-mm-dd * @param isoDate * @return the year from an iso date */ public static Integer getYearFromISODate(String isoDate) { Integer year = null; if (isoDate.matches("\\d{4}")) { // must just be year year = new Integer(isoDate); } else if (isoDate.matches("\\d{4}-\\d{2}") || isoDate.matches("\\d{4}-\\d{2}-\\d{2}")) { String[] sa = isoDate.split("-"); year = new Integer(sa[0]); } else if (isoDate.matches("\\d{8}")) { //looks like YYYYMMDD String stringYear = isoDate.substring(0, 4); year = new Integer(stringYear); } return year; } }