Java Today getToday()

Here you can find the source of getToday()

Description

Get today's date as per local calendar.

License

Open Source License

Return

a date object that represents a UTC date that is equal to today in local calendar. for example, if local calendar says 20-Aug-2016, but UTC would say 21-Aug-2016, this function returns date that would print in UTC as '2016-08-20T00:00:00.000Z'

Declaration

public static Date getToday() 

Method Source Code

//package com.java2s;
/*/*from ww  w  . j  av  a2 s.c  om*/
 * Copyright (c) 2016 simplity.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

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

public class Main {
    /**
     * Get today's date as per local calendar.
     *
     * @return a date object that represents a UTC date that is equal to today
     *         in local calendar. for example, if local calendar says
     *         20-Aug-2016, but UTC would say 21-Aug-2016, this function returns
     *         date that would print in UTC as '2016-08-20T00:00:00.000Z'
     */
    public static Date getToday() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        /*
         * set date to this millis
         */
        return cal.getTime();
    }
}

Related

  1. getTimeNumberToday()
  2. getToday()
  3. getToday()
  4. getToday()
  5. getToday()
  6. getToday()
  7. getToday()
  8. getToday()
  9. getToday()