Java Calendar Parse getCalendar(Object source)

Here you can find the source of getCalendar(Object source)

Description

get Calendar

License

Open Source License

Declaration

public static Calendar getCalendar(Object source) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Calendar getCalendar(Object source) {

        String d = getString(source);
        Calendar c = Calendar.getInstance();
        TimeZone t = TimeZone.getTimeZone("Etc/Universal");
        c.setTimeZone(t);//from  w  ww  .  ja  va 2 s. c  o m
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        s.setTimeZone(t);

        try {
            c.setTime(s.parse(d));
            return c;
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }

        return null;

    }

    public static String getString(Object o) {
        if (o == null)
            return null;
        return o.toString();
    }
}

Related

  1. convertStringToCalendar(String time)
  2. getCalendarObject(String value, boolean hasMills)
  3. str2Calendar(String pString)
  4. str2Calendar(String str, String format)
  5. string2Calendar(String data)