Java SQL Date From getCurrentDateTime()

Here you can find the source of getCurrentDateTime()

Description

get Current Date Time

License

Apache License

Declaration

public static String getCurrentDateTime() 

Method Source Code


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

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

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

    public static String getCurrentDateTime() {
        return getCurrentTime(DEFAULT_DATE_PATTERN);
    }//from w  ww .  ja  v a  2  s  . co  m

    public static String getCurrentTime() {
        return getCurrentTime(DEFAULT_TIME_PATTERN);
    }

    public static String getCurrentTime(String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        return sdf.format(timestamp);
    }
}

Related

  1. convertToTime(Date toDate)
  2. convertToTime(java.util.Date date)
  3. getCNTimezone()
  4. getCurAllTime()
  5. getCurrDateTime()
  6. getCurrentTime()
  7. getCurrentTime()
  8. getCurrentTime()
  9. getCurrentTime(String format)