Here you can find the source of getISODateInSeconds(String isoDate)
Parameter | Description |
---|---|
isoDate | The isodate to convert to seconds |
public static Long getISODateInSeconds(String isoDate)
//package com.java2s; /**/*from w ww.java2 s .c om*/ * 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. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * Method to get an iso date in the format yyyy, yyyy-mm, or yyyy-mm-dd in GMT seconds * @param isoDate The isodate to convert to seconds * @return GMT Seconds representing the given date */ public static Long getISODateInSeconds(String isoDate) { String dateString = ""; SimpleDateFormat isodf = new SimpleDateFormat("yyyy-MM-dd"); // first check the format of the isodate to see if anything need to be added to // get it to the yyyy-mm-dd format if (isoDate.matches("\\d{4}")) { // must just be year so add 1st month and 1st day dateString = isoDate + "-01-01"; } else if (isoDate.matches("\\d{4}-\\d{2}")) { // must be yyyy-mm so add 1st day dateString = isoDate + "-01"; } else if (isoDate.matches("\\d{8}")) { // must be YYYYMMDD dateString = isoDate; isodf = new SimpleDateFormat("yyyyMMdd"); } else { // must be full date so use that dateString = isoDate; } // now convert to java date object and get the seconds from that try { Date testDate = isodf.parse(dateString); return testDate.getTime(); } catch (ParseException pe) { return null; } } }