Java Today today()

Here you can find the source of today()

Description

today

License

Apache License

Return

Gets a calendar instance pointing to 00:00:00 of current day

Declaration

static Calendar today() 

Method Source Code

//package com.java2s;
/**// w  w w . java 2s  . co m
 Copyright 2016 Just10 Inc.
    
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import java.util.Calendar;

public class Main {
    /**
     @return Gets a calendar instance pointing to 00:00:00 of current day
     */
    static Calendar today() {
        return setMidnight(now());
    }

    static Calendar setMidnight(final Calendar date) {
        date.set(Calendar.HOUR_OF_DAY, 0);
        date.set(Calendar.MINUTE, 0);
        date.set(Calendar.SECOND, 0);
        date.set(Calendar.MILLISECOND, 0);
        return date;
    }

    /**
     Gets the current time
     @return current time
     */
    static Calendar now() {
        return Calendar.getInstance();
    }
}

Related

  1. startOfToday()
  2. today()
  3. Today()
  4. today()
  5. today()
  6. today()
  7. today()
  8. today()
  9. today()