Java Today converTimeToDayStartEnd(long time, long[] out)

Here you can find the source of converTimeToDayStartEnd(long time, long[] out)

Description

convert a time to the corresponding time of the start and end of the day it exists on.

License

Open Source License

Parameter

Parameter Description
time a parameter

Declaration

public static long[] converTimeToDayStartEnd(long time, long[] out) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from   w  w w  .  j a  va  2 s .  com
     * convert a time to the corresponding time of the start and end of
     * the day it exists on.
     *
     * @param time
     * @return
     */
    public static long[] converTimeToDayStartEnd(long time, long[] out) {
        Calendar cal = new GregorianCalendar();
        Calendar calEnd = new GregorianCalendar();
        cal.setTime(new Date(time));
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        calEnd.setTime(cal.getTime());
        calEnd.add(Calendar.DATE, 1); // add one day to end date

        if (out == null) {
            return new long[] { cal.getTimeInMillis(), calEnd.getTimeInMillis() };
        } else {
            out[0] = cal.getTimeInMillis();
            out[1] = calEnd.getTimeInMillis();
            return out;
        }

    }
}

Related

  1. afterToday(String date)
  2. beforeToday(int days)
  3. createTodayDirectory(File destDir)
  4. createTodayDirectory(File destDir, String inputFileName)
  5. createTodayPrefixedDirectory(final String prefix, final File parent)
  6. deletePreviousDay(Calendar today, String temppath)