Java String to Time stringToCalendar(String stringTime)

Here you can find the source of stringToCalendar(String stringTime)

Description

string To Calendar

License

Apache License

Declaration

public static Calendar stringToCalendar(String stringTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Calendar stringToCalendar(String stringTime, String pattern) {
        if ((stringTime != null) && (!(stringTime.isEmpty()))) {
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            try {
                Date time = format.parse(stringTime);
                Calendar c = Calendar.getInstance();
                c.setTime(time);//from w w  w .java  2 s . c o  m
                return c;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static Calendar stringToCalendar(String stringTime) {
        return stringToCalendar(stringTime, "yyyyMMddHHmmss");
    }
}

Related

  1. replaceDateTime(String input)
  2. str2DateTime(String strDate)
  3. string2Date(String time)
  4. string2DateTime(String stringDate)
  5. string2DateTimeByAutoZero(String stringDate)
  6. stringToCalendar(String timeStr)
  7. stringToTimeDate(String timeStr)
  8. toTime(final String dateString)
  9. toTime(String display)