Java Calendar Create createCalendarFromParts(String[] parts)

Here you can find the source of createCalendarFromParts(String[] parts)

Description

create Calendar From Parts

License

Open Source License

Declaration

private static Calendar createCalendarFromParts(String[] parts) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of zdt2go./*from  w w  w .  j  a  va2 s . c  o  m*/
 * Copyright (c) 2009 Achim Weimert.
 * http://code.google.com/p/zdt2go/
 * 
 * zdt2go is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * zdt2go is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with zdt2go.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     Achim Weimert - initial API and implementation
 ******************************************************************************/

import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    private static final int MONTH = 0;
    private static final int DAY = 1;
    private static final int YEAR = 2;
    private static final int HOUR = 3;
    private static final int MINUTE = 4;

    private static Calendar createCalendarFromParts(String[] parts) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(TimeZone.getDefault());
        calendar.set(Calendar.YEAR, Integer.parseInt(parts[YEAR]));
        calendar.set(Calendar.MONTH, Integer.parseInt(parts[MONTH]) - 1);
        calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parts[DAY]));
        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[HOUR]));
        calendar.set(Calendar.MINUTE, Integer.parseInt(parts[MINUTE]));
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }
}

Related

  1. createCalendar(int year, int month, int date)
  2. createCalendar(int year, int month, int day)
  3. createCalendar(int year, int month, int day, int hour, int minute, int second, boolean ceiling)
  4. createCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second)
  5. createCalendar(long timeInMillis)
  6. createCalendarInstance(final Locale locale)
  7. createCalendarMidnight(final Date date)
  8. createCalendarWith()
  9. createDateFormatString(Calendar cal)