Java Calendar Create getCalendar(long timeInMillis)

Here you can find the source of getCalendar(long timeInMillis)

Description

Get Calendar object representing the specified time in millis.

License

Open Source License

Parameter

Parameter Description
timeInMillis Time in milli seconds

Return

Calendar object

Declaration

public static Calendar getCalendar(long timeInMillis) 

Method Source Code

//package com.java2s;
/*/*ww  w  .ja  v a  2s .c  o m*/
 * Copyright (c) 2010,2012 Daniel Marell
 * All rights reserved.
 *
 * Permission is hereby granted, free  of charge, to any person obtaining
 * a  copy  of this  software  and  associated  documentation files  (the
 * "Software"), to  deal in  the Software without  restriction, including
 * without limitation  the rights to  use, copy, modify,  merge, publish,
 * distribute,  sublicense, and/or sell  copies of  the Software,  and to
 * permit persons to whom the Software  is furnished to do so, subject to
 * the following conditions:
 *
 * The  above  copyright  notice  and  this permission  notice  shall  be
 * included in all copies or substantial portions of the Software.
 *
 * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
 * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
 * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.util.Calendar;

public class Main {
    /**
     * Get Calendar object representing the specified time in millis.
     *
     * @param timeInMillis Time in milli seconds
     * @return Calendar object
     */
    public static Calendar getCalendar(long timeInMillis) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeInMillis);
        return calendar;
    }

    /**
     * Get Calendar object for date.
     *
     * @param year  Year yyyy
     * @param month Month 1-12
     * @param day   Day of month 1-31
     * @return Calendar object
     */
    public static Calendar getCalendar(int year, int month, int day) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.DAY_OF_MONTH, day);
        return c;
    }
}

Related

  1. getCalendar(int year, int month, int day, int hours, int minutes, int seconds, TimeZone tz)
  2. getCalendar(int year, int month, int day, TimeZone timeZone)
  3. getCalendar(long millis)
  4. getCalendar(long millis)
  5. getCalendar(long time)
  6. getCalendar(long timeInMillis)
  7. getCalendar(String date)
  8. getCalendar(String dateStr, int inputYearType, int outputYearType)
  9. getCalendar(String dateString)