Java Millisecond to Hour time2millis(int year, int mon, int day, int hours, int mins, int secs)

Here you can find the source of time2millis(int year, int mon, int day, int hours, int mins, int secs)

Description

Converts Gregorian date to milliseconds since 1970-01-01 00:00:00 .

License

Open Source License

Parameter

Parameter Description
year the year
mon the month 1..12
day the day of month 1..31
hours hours of day 0..23
mins minutes 0..59
secs seconds 0..59

Return

the milliseconds since 1970-01-01 00:00:00

Declaration

public static long time2millis(int year, int mon, int day, int hours, int mins, int secs) 

Method Source Code

//package com.java2s;
/*//from  w w w  .ja  v  a  2s  . c  om
 * $Id$
 *
 * Copyright (C) 2003-2015 JNode.org
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library 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 Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; If not, write to the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

public class Main {
    /**
     * Converts Gregorian date to milliseconds since 1970-01-01 00:00:00 .
     *
     * @param year  the year
     * @param mon   the month 1..12
     * @param day   the day of month 1..31
     * @param hours hours of day 0..23
     * @param mins  minutes 0..59
     * @param secs  seconds 0..59
     * @return the milliseconds since 1970-01-01 00:00:00
     */
    public static long time2millis(int year, int mon, int day, int hours, int mins, int secs) {
        if (0 >= (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
            mon += 12; /* Puts Feb last since it has leap day */
            year -= 1;
        }

        return ((((((long) (year / 4 - year / 100 + year / 400 + 367 * mon / 12 + day) + year * 365
                - 719499)) /* days */
                * 24l + hours) /* hours */
                * 60l + mins) /* minutes */
                * 60l + secs) /* seconds */
                * 1000l; /* milliseconds */
    }
}

Related

  1. milliseconds(long p_days, long p_hours, long p_minutes, long p_hoursPerBusinessDay)
  2. millisecondsToHours(long ms)
  3. millisecondToHour(Long millisecond)
  4. millisToHours(double millis)
  5. millisToHours(long millis)
  6. timeAsMillis(int days, int hours, int minutes, int seconds, int millis)
  7. timeToMillis(int hours, int minutes, int seconds, int millis)