Java Date Convert convertDateToLong(int year, int month, int day, int hour, int minute, int second)

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

Description

convert a given date to long representation

License

Open Source License

Parameter

Parameter Description
year a parameter
month a parameter
day a parameter
hour a parameter
minute a parameter
second a parameter

Return

the long representation of the given time

Declaration

public static long convertDateToLong(int year, int month, int day, int hour, int minute, int second) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**//from w ww.  ja  va 2s .c  o m
     * convert a given date to long representation
     * 
     * @param year   
     * @param month
     * @param day
     * @param hour
     * @param minute
     * @param second
     * @return   the long representation of the given time
     */
    public static long convertDateToLong(int year, int month, int day, int hour, int minute, int second) {
        Date d = getDate(year, month, day, hour, minute, second);
        return d.getTime();
    }

    /**
     * get Date object with given values
     * 
     * @param year
     * @param month
     * @param day
     * @param hour
     * @param minute
     * @param second
     * @return
     */
    public static Date getDate(int year, int month, int day, int hour, int minute, int second) {
        Calendar c = new GregorianCalendar();
        c.set(year, month - 1, day);
        c.set(Calendar.HOUR, hour);
        c.set(Calendar.MINUTE, minute);
        c.set(Calendar.SECOND, second);
        c.set(Calendar.AM_PM, Calendar.AM);
        return c.getTime();
    }
}

Related

  1. convertDateTime(String date, String time)
  2. convertDateTimeToSysTime(String sDateTime)
  3. ConvertDateToAge(String date)
  4. convertDateToDoubleTime(Date time)
  5. convertDateToInt(final Date date)
  6. convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond)
  7. convertDateToTimeStamp(Date date)
  8. convertDateToUTC(Date date)
  9. convertDateToWindowsTime(Date javaDate)