Java SQL Date Create currentDate()

Here you can find the source of currentDate()

Description

current Date

License

Open Source License

Declaration

public static synchronized Date currentDate() 

Method Source Code


//package com.java2s;
/*//ww  w  . ja v a2  s  . co  m
 * Este programa es software libre; usted puede redistribuirlo y/o modificarlo bajo los t?rminos
 * de la licencia "GNU General Public License" publicada por la Fundaci?n "Free Software Foundation".
 * Este programa se distribuye con la esperanza de que pueda ser ?til, pero SIN NINGUNA GARANTIA;
 * vea la licencia "GNU General Public License" para obtener mas informaci?n.
 */

import java.sql.Date;

import java.util.Calendar;

public class Main {
    private static long currentTimeMillis = 0;
    private static long lastTimeMillis = 0;
    private static long lastTimeMicros = 0;
    private static long lastTimeNanos = 0;
    private static long micros = 0;
    private static long nanos = 0;
    private static Calendar calendar = Calendar.getInstance();

    public static synchronized Date currentDate() {
        calendar.setTimeInMillis(currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return new Date(calendar.getTimeInMillis());
    }

    public static synchronized long currentTimeMillis() {
        currentTimeMillis = System.currentTimeMillis();
        if (lastTimeMillis < currentTimeMillis) {
            lastTimeMillis = currentTimeMillis;
        } else {
            lastTimeMillis++;
        }
        lastTimeMicros = lastTimeMillis * 1000;
        lastTimeNanos = lastTimeMicros * 1000;
        micros = 0;
        nanos = 0;
        return lastTimeMillis;
    }
}

Related

  1. createRecGetStatementsUpdate(String tip, String imeFirstCap)
  2. createSqlDate(String dateStr)
  3. createStreamingStatement(Connection conn, boolean update)
  4. createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)
  5. currentDate()
  6. currentDate()
  7. getCurrDate()
  8. getCurrentDate()
  9. getCurrentDate()