Java Date to Timestamp getTimestamp(Date date)

Here you can find the source of getTimestamp(Date date)

Description

get Timestamp

License

Open Source License

Declaration

public static synchronized Date getTimestamp(Date date) 

Method Source Code


//package com.java2s;
/*/*from  w  w w .  ja  v a2 s .  com*/
 * Copyright (C) 2008, EGT Consultores, C.A.
 *
 * 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.Timestamp;

import java.util.Date;

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;

    public static synchronized Date getTimestamp() {
        return currentTimestamp();
    }

    public static synchronized Date getTimestamp(Date date) {
        return date == null ? currentTimestamp() : date;
    }

    public static synchronized Timestamp currentTimestamp() {
        return new Timestamp(currentTimeMillis());
    }

    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. getJnlpTimestamp(Date date)
  2. getTimestamp(Date date)
  3. getTimestamp(Date date)
  4. getTimestamp(Date date)
  5. getTimestamp(Date date)
  6. getTimestamp(Date date)
  7. getTimestamp(Date date)
  8. getTimestamp(Date date)
  9. getTimestamp(Date date)