Java Today getToday()

Here you can find the source of getToday()

Description

getToday: returns today

License

Apache License

Return

Date with no time {talendTypes} Date {Category} TimestampUtil {example} getToday().

Declaration

public static java.util.Date getToday() 

Method Source Code

//package com.java2s;
/**//from w  ww  . j  a  va  2s . c om
 * Copyright 2015 Jan Lolling jan.lolling@gmail.com
 * 
 * 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.Date;

public class Main {
    /**
     * getToday: returns today
     * @return Date with no time
     * 
     * {talendTypes} Date
     * 
     * {Category} TimestampUtil
     * 
     * {example} getToday().
     */
    public static java.util.Date getToday() {
        return truncateToDay(new Date());
    }

    /**
     * truncateToDay: returns the start of the given day.
     * 
     * {Category} TimestampUtil
     * 
     * {talendTypes} Date
     * 
     * {param} Date() day: any day.
     * 
     * {example} truncateToDay(TalendDate.getCurentDate()).
     */
    public static java.util.Date truncateToDay(java.util.Date timestamp) {
        if (timestamp == null)
            return null;
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(timestamp);
        // cut time
        c.set(java.util.Calendar.MINUTE, 0);
        c.set(java.util.Calendar.SECOND, 0);
        c.set(java.util.Calendar.MILLISECOND, 0);
        c.set(java.util.Calendar.HOUR_OF_DAY, 0);
        return c.getTime();
    }
}

Related

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