Java Today getToday()

Here you can find the source of getToday()

Description

Returns the date representing today (by system time) without time

License

Open Source License

Declaration

public static Date getToday() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 Ralf Ebert/*  w ww.  j a  v a  2  s. c  om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Ralf Ebert - initial API and implementation
 *******************************************************************************/

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

public class Main {
    /**
     * Returns the date representing today (by system time) without time
     * 
     * @return
     */
    public static Date getToday() {
        Calendar c = Calendar.getInstance();
        setZeroTime(c);
        return c.getTime();
    }

    /**
     * Sets hour, minute, second, millisecond set to 0 for the given Calendar
     * object
     * 
     * @param c
     *            Calendar object
     */
    private static void setZeroTime(Calendar c) {
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
    }
}

Related

  1. getStartOfDayRelative(int daysFromToday)
  2. getStartOfToday()
  3. getStartOfToday()
  4. getStringToday()
  5. getTimeNumberToday()
  6. getToday()
  7. getToday()
  8. getToday()
  9. getToday()