Java Day getLastTimeInDay(Date day)

Here you can find the source of getLastTimeInDay(Date day)

Description

get Last Time In Day

License

Apache License

Declaration

public static Date getLastTimeInDay(Date day) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static Date getLastTimeInDay(Date day) {
        Calendar date = Calendar.getInstance();
        date.setTime(getFirstTimeInDay(day));
        date.add(Calendar.DAY_OF_YEAR, 1);
        date.add(Calendar.SECOND, -1);
        return date.getTime();
    }/* w  w w  .  ja v a  2s  .co m*/

    public static Date getFirstTimeInDay(Date day) {
        Calendar date = Calendar.getInstance();
        date.setTime(day);
        date.set(Calendar.HOUR_OF_DAY, 0);
        date.set(Calendar.MINUTE, 0);
        date.set(Calendar.SECOND, 0);
        date.set(Calendar.MILLISECOND, 0);
        return date.getTime();
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String min;
        min = dateString.substring(14, 16);
        return min;
    }
}

Related

  1. getLastDay(Date date)
  2. getLastDay(Date date)
  3. getLastDay(String nowdate, String inFormat, String outFormat)
  4. getLastDayOfQuarter(Date date)
  5. getLastNDays(int aInN)