Here you can find the source of timestamp17ToCalendar(String timestamp17String)
Parameter | Description |
---|---|
timestamp17String | a parameter |
timestamp17String
.
public static Calendar timestamp17ToCalendar(String timestamp17String)
//package com.java2s; /*//from w w w . ja v a 2 s .c o m * ArchiveUtils * * $Header: /cvsroot/archive-crawler/ArchiveOpenCrawler/src/java/org/archive/util/ArchiveUtils.java,v 1.38 2007/01/23 00:29:48 gojomo Exp $ * * Created on Jul 7, 2003 * * Copyright (C) 2003 Internet Archive. * * This file is part of the Heritrix web crawler (crawler.archive.org). * * Heritrix is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * any later version. * * Heritrix 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 * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with Heritrix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ import java.util.Calendar; import java.util.GregorianCalendar; public class Main { /** * Convert 17-digit date format timestamps (as found in crawl.log, for * example) into a GregorianCalendar object. + * Useful so you can convert * into milliseconds-since-epoch. Note: it is possible to compute * milliseconds-since-epoch + * using {@link #parse17DigitDate}.UTC(), but * that method is deprecated in favor of using Calendar.getTimeInMillis(). + * * <p/>I probably should have dug into all the utility methods in * DateFormat.java to parse the timestamp, but this was + * easier. If * someone wants to fix this to use those methods, please have at it! <p/> * Mike Schwartz, schwartz at CodeOnTheRoad dot com. * * @param timestamp17String * @return Calendar set to <code>timestamp17String</code>. */ public static Calendar timestamp17ToCalendar(String timestamp17String) { GregorianCalendar calendar = new GregorianCalendar(); int year = Integer.parseInt(timestamp17String.substring(0, 4)); int dayOfMonth = Integer.parseInt(timestamp17String.substring(6, 8)); // Month is 0-based int month = Integer.parseInt(timestamp17String.substring(4, 6)) - 1; int hourOfDay = Integer.parseInt(timestamp17String.substring(8, 10)); int minute = Integer.parseInt(timestamp17String.substring(10, 12)); int second = Integer.parseInt(timestamp17String.substring(12, 14)); int milliseconds = Integer.parseInt(timestamp17String.substring(14, 17)); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, milliseconds); return calendar; } }