Android Calendar Parse getDesignatedCalendar(String unformattedTime)

Here you can find the source of getDesignatedCalendar(String unformattedTime)

Description

get Designated Calendar

Declaration

public static Calendar getDesignatedCalendar(String unformattedTime) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static Calendar getDesignatedCalendar(String unformattedTime) {

        // ( "2011-03-02T12:46:06Z" | "2011-03-02T12:46:06+09:00" ) ->
        // "2011/03/02 21:46:06"
        unformattedTime = unformattedTime.replaceAll("(\\+[0-9+:]+)|Z", "");
        String[] updateTimes = unformattedTime.substring(0,
                unformattedTime.length()).split("T");
        String[] date = updateTimes[0].split("-");
        String[] times = updateTimes[1].split(":");
        int year = Integer.parseInt(date[0]);
        int month = Integer.parseInt(date[1]);
        int day = Integer.parseInt(date[2]);
        int hour = Integer.parseInt(times[0]);
        int minute = Integer.parseInt(times[1]);
        int second = Integer.parseInt(times[2]);

        Calendar cal = new GregorianCalendar(year, month - 1, day, hour,
                minute, second);/*from   www  . j ava  2 s  .  co  m*/
        cal.add(Calendar.HOUR, 9);

        return cal;
    }
}

Related

  1. pars2Calender(String s)
  2. stringToCalendar(String date)
  3. convertStringToCalendar(String stringDate)
  4. getCalendarFromString(String time)
  5. getSelectCalendar(String dateStr, String pattern)