Java Month of Year getTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond)

Here you can find the source of getTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond)

Description

get Timestamp

License

Open Source License

Declaration

static Date getTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Open Software Solutions GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 * //from www .j  a  va  2  s.  co m
 * Contributors:
 *     Open Software Solutions GmbH
 ******************************************************************************/

import java.util.Calendar;
import java.util.Date;

public class Main {
    static Date getTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond) {
        Calendar cal = Calendar.getInstance();
        cal.clear();
        setDate(cal, year, month, day);
        setTime(cal, hour, minute, second);
        cal.set(Calendar.MILLISECOND, millisecond);
        return cal.getTime();
    }

    private static void setDate(Calendar cal, int year, int month, int day) {
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DATE, day);
    }

    private static void setTime(Calendar cal, int hour, int minute, int second) {
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        cal.set(Calendar.SECOND, second);
    }

    static Date getTime(int hour, int minute, int second) {
        Calendar cal = Calendar.getInstance();
        cal.clear();
        setTime(cal, hour, minute, second);
        return cal.getTime();
    }
}

Related

  1. getStartAndEndOfMonth(int month, int year)
  2. getStrDayOfWeek(int _year, int _month, int _day)
  3. getThisMonth(int year, int monthIndex)
  4. getTime(int year, int month, int day)
  5. getTimeByYMD(int year, int month, int day)
  6. getTodayAdd(int year, int month, int day)
  7. getWeek(int year, int month, int day)
  8. getWorkDayNum(int year, int month, int start, int end)
  9. isDefaultHolidays(int year, int month, int day)