Java Timestamp getTodayTimestamp()

Here you can find the source of getTodayTimestamp()

Description

get Today Timestamp

License

Apache License

Return

timestamp at midnight for current day (this is the very beginning of a day NOT the end)

Declaration

public static Timestamp getTodayTimestamp() 

Method Source Code

//package com.java2s;
/*//from w ww. j  a  va 2 s .  com
 * Copyright (c) Jim Coles (jameskcoles@gmail.com) 2018 through present.
 *
 * Licensed under the following license agreement:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Also see the LICENSE file in the repository root directory.
 */

import java.sql.*;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    /**
     * @return timestamp at midnight for current day (this is the very
     * beginning of a day NOT the end)
     */
    public static Timestamp getTodayTimestamp() {
        Calendar cal = new GregorianCalendar();
        cal.set(GregorianCalendar.HOUR, 0);
        cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
        cal.set(GregorianCalendar.MINUTE, 0);
        cal.set(GregorianCalendar.SECOND, 0);
        cal.set(GregorianCalendar.MILLISECOND, 0);
        long todayInMillis = cal.getTime().getTime();
        Timestamp ts = new Timestamp(todayInMillis);
        return ts;
    }
}

Related

  1. getTimeNextMonthFirstSec(Timestamp sysDate)
  2. getTimePassedSince(Timestamp timestamp)
  3. getTimeStr(Timestamp tsp)
  4. getTimeString(java.sql.Timestamp ts)
  5. getTimeString(Timestamp timestamp)
  6. getUtilDate(java.sql.Timestamp time)
  7. getValue(Timestamp t)
  8. getZonedDateTime(final Timestamp timestamp)
  9. hasTimeExpired(Timestamp referenceTime)