Java TimeUnit Usage getDayFromTimestamp(final long unixTimestamp)

Here you can find the source of getDayFromTimestamp(final long unixTimestamp)

Description

get Day From Timestamp

License

Open Source License

Parameter

Parameter Description
unixTimestamp in seconds

Return

0 for sunday, 1 for monday, etc

Declaration

public static int getDayFromTimestamp(final long unixTimestamp) 

Method Source Code

//package com.java2s;
/*//from w  w  w . j a  va  2 s. c  om
 * Copyright ? R?gion Nord Pas de Calais-Picardie,  D?partement 91, R?gion Aquitaine-Limousin-Poitou-Charentes, 2016.
 *
 * This file is part of OPEN ENT NG. OPEN ENT NG is a versatile ENT Project based on the JVM and ENT Core Project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation (version 3 of the License).
 *
 * For the sake of explanation, any module that communicate over native
 * Web protocols, such as HTTP, with OPEN ENT NG is outside the scope of this
 * license and could be license under its own terms. This is merely considered
 * normal use of OPEN ENT NG, and does not fall under the heading of "covered work".
 *
 * This program 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.
 */

import java.util.Calendar;

import java.util.concurrent.TimeUnit;

public class Main {
    /**
     *
     * @param unixTimestamp in seconds
     * @return 0 for sunday, 1 for monday, etc
     */
    public static int getDayFromTimestamp(final long unixTimestamp) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(TimeUnit.MILLISECONDS.convert(unixTimestamp, TimeUnit.SECONDS));
        // "- 1", so that sunday is 0, monday is 1, etc
        int day = cal.get(Calendar.DAY_OF_WEEK) - 1;

        return day;
    }
}

Related

  1. getCurrentTimestamp()
  2. getCurrentTimestampInSeconds()
  3. getDate(final int oceanTime)
  4. getDateBefore(final Date day)
  5. getDateWithoutTime(final Calendar calendar)
  6. getDays(final long ms)
  7. getDays(long endTs, Long lookback)
  8. getDeltaBetweenTimestamps(final long start, final long end)
  9. getDifferenceDays(Date d1, Date d2)