Java String to Time getCalendarFromDate(final String dateTime)

Here you can find the source of getCalendarFromDate(final String dateTime)

Description

getCalendarFromDate.

License

Open Source License

Parameter

Parameter Description
dateTime a java.lang.String object.

Return

a object.

Declaration

public static Calendar getCalendarFromDate(final String dateTime) 

Method Source Code

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**/*from  w  w w .j a va 2s.  c  o  m*/
     * <p>getCalendarFromDate.</p>
     *
     * @param dateTime a {@link java.lang.String} object.
     * @return a {@link java.util.Calendar} object.
     */
    public static Calendar getCalendarFromDate(final String dateTime) {
        final Calendar cal = GregorianCalendar.getInstance();
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            final Date date = sdf.parse(dateTime);
            cal.setTime(date);
        } catch (final ParseException e) {
            return null;
        }
        return cal;
    }
}

Related

  1. getAsDateTime(String dateTime)
  2. getCalendarForSpecifiedDate(final String dateTime)
  3. getCalendarFromCPEGeneratorDateTime(String cpeDateTime)
  4. getDlayDateTime(String playDate, String playTime)
  5. getEndTime(String flag, int value)
  6. getExecutionDateTime(String input)
  7. getExpireTime(String timeStr)