Java SQL Date From getCurrentTime()

Here you can find the source of getCurrentTime()

Description

get Current Time

License

Apache License

Declaration

public static String getCurrentTime() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String getCurrentTime() {
        return getDateString(DATETIME_FORMAT);
    }/*from   w w  w .jav  a2 s .c  o  m*/

    public static String getDateString(String pattern) {
        Timestamp time = getSysDate();
        DateFormat dfmt = new SimpleDateFormat(pattern);
        java.util.Date date = time;
        return dfmt.format(date);
    }

    public static String getDateString(Timestamp time, String pattern) {
        DateFormat dfmt = new SimpleDateFormat(pattern);
        java.util.Date date = time;
        return date != null ? dfmt.format(date) : "";
    }

    public static String getDateString(Date date, String pattern) {
        SimpleDateFormat sdfmt = new SimpleDateFormat(pattern);
        return date != null ? sdfmt.format(date) : "";
    }

    public static Timestamp getSysDate() {
        return new Timestamp(System.currentTimeMillis());
    }
}

Related

  1. getCurAllTime()
  2. getCurrDateTime()
  3. getCurrentDateTime()
  4. getCurrentTime()
  5. getCurrentTime()
  6. getCurrentTime(String format)
  7. getCurrentTimeMillis()
  8. GetCurrFormattedDateTime(String strFormatTo)
  9. getCurrTime()