Here you can find the source of calenderFromDateString(String dateAndTime)
Parameter | Description |
---|---|
dateAndTime | the date and time string to convert |
public static Calendar calenderFromDateString(String dateAndTime)
//package com.java2s; /*/*from w w w .j a v a2 s. c o m*/ * JGrass - Free Open Source Java GIS http://www.jgrass.org * (C) HydroloGIS - www.hydrologis.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.GregorianCalendar; public class Main { /** * Transforms a date and time string of the format:<br> * <i>dd/mm/yyyy hh:mm:ss</i><br> * to a calendar object. * * @param dateAndTime the date and time string to convert * @return the generated calendar object */ public static Calendar calenderFromDateString(String dateAndTime) { String[] dateTime = dateAndTime.trim().split(" "); String datetoken = dateTime[0]; String timetoken = dateTime[1]; String[] startDay = datetoken.trim().split("/"); String[] startHour = timetoken.trim().split(":"); return new GregorianCalendar(Integer.parseInt(startDay[2]), Integer.parseInt(startDay[1]) - 1, Integer.parseInt(startDay[0]), Integer.parseInt(startHour[0]), Integer.parseInt(startHour[1]), Integer.parseInt(startHour[2])); } }