Java Calendar Parse getCalendarObject(String value, boolean hasMills)

Here you can find the source of getCalendarObject(String value, boolean hasMills)

Description

get Calendar Object

License

Apache License

Declaration

private static Calendar getCalendarObject(String value, boolean hasMills) 

Method Source Code


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

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

public class Main {
    protected static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    protected static final SimpleDateFormat SIMPLE_DATE_FORMAT_MILLS = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSS");

    private static Calendar getCalendarObject(String value, boolean hasMills) {
        try {// w w w  .j  av a  2 s  .  co  m
            Calendar calendar = Calendar.getInstance();
            if (hasMills) {
                calendar.setTime(SIMPLE_DATE_FORMAT_MILLS.parse(value));
            } else {
                calendar.setTime(SIMPLE_DATE_FORMAT.parse(value));
            }
            return calendar;
        } catch (ParseException e) {
        }
        return null;
    }
}

Related

  1. convertStringToCalendar(String time)
  2. getCalendar(Object source)
  3. str2Calendar(String pString)
  4. str2Calendar(String str, String format)
  5. string2Calendar(String data)
  6. stringCalendar(Calendar cal)