Java Calendar Second getTimestampInDayFirstSecond(final Calendar calendar)

Here you can find the source of getTimestampInDayFirstSecond(final Calendar calendar)

Description

get Timestamp In Day First Second

License

Apache License

Declaration

public static int getTimestampInDayFirstSecond(final Calendar calendar) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static final int MILLIS_PER_SECOND = 1000;

    public static int getTimestampInDayFirstSecond(final Calendar calendar) {
        Calendar other = (Calendar) calendar.clone();
        other.set(Calendar.HOUR_OF_DAY, 0);
        other.set(Calendar.MINUTE, 0);
        other.set(Calendar.SECOND, 0);
        other.set(Calendar.MILLISECOND, 0);
        return getTimestamp(other.getTimeInMillis());
    }//from  w ww  . jav a 2  s .  co m

    public static int getTimestampInDayFirstSecond(int ts) {
        Calendar other = Calendar.getInstance();
        other.setTimeInMillis(Integer.toUnsignedLong(ts) * MILLIS_PER_SECOND);
        other.set(Calendar.HOUR_OF_DAY, 0);
        other.set(Calendar.MINUTE, 0);
        other.set(Calendar.SECOND, 0);
        other.set(Calendar.MILLISECOND, 0);
        return getTimestamp(other.getTimeInMillis());
    }

    public static int getTimestampInDayFirstSecond(long timeInMillis) {
        Calendar other = Calendar.getInstance();
        other.setTimeInMillis(timeInMillis);
        other.set(Calendar.HOUR_OF_DAY, 0);
        other.set(Calendar.MINUTE, 0);
        other.set(Calendar.SECOND, 0);
        other.set(Calendar.MILLISECOND, 0);
        return getTimestamp(other.getTimeInMillis());
    }

    public static int getTimestamp() {
        return (int) (System.currentTimeMillis() / MILLIS_PER_SECOND);
    }

    public static int getTimestamp(long timeInMillis) {
        return (int) (timeInMillis / MILLIS_PER_SECOND);
    }

    public static int getTimestamp(final Date date) {
        return (int) (date.getTime() / MILLIS_PER_SECOND);
    }
}

Related

  1. getSecond(Calendar calendar)
  2. getSecondsSinceMidnight(Calendar c)
  3. getSecondsSinceMidnight(final Calendar time)
  4. getTimeInSeconds(Calendar t)
  5. getTimeSeconds(Calendar cal)
  6. hasPassed10Second(Calendar time)
  7. isFirstAfterSecond(Calendar first, Calendar second)
  8. isSameSecond(Calendar c1, Calendar c2)
  9. moveToCalendarSecondJustFor(Calendar cal, int second)