Java Day End calenderFromDateString(String dateAndTime)

Here you can find the source of calenderFromDateString(String dateAndTime)

Description

Transforms a date and time string of the format:
dd/mm/yyyy hh:mm:ss
to a calendar object.

License

Open Source License

Parameter

Parameter Description
dateAndTime the date and time string to convert

Return

the generated calendar object

Declaration

public static Calendar calenderFromDateString(String dateAndTime) 

Method Source Code


//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]));
    }
}

Related

  1. absoluteDay(Calendar cal)
  2. calculateMaxStartDate(Calendar calendar, int daysAhead)
  3. calcYears(Date startDate, Date endDate)
  4. checkTimeInRangeWithSkew(Date timeToCheck, Date startDate, Date endDate, int skewInMinutes)
  5. checkTimePeriod(final Date beginHour, final Date endHour, final Date hour)
  6. countDaysBetween(Date start, Date end)
  7. countMonths(java.util.Date startDate, java.util.Date endDate)