Java SQL Time Now currentDatetime()

Here you can find the source of currentDatetime()

Description

current Datetime

License

Apache License

Declaration

public static String currentDatetime() 

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 final static String STANDARD_DATE_PATTERN = "yyyy-MM-dd";

    public static String currentDatetime() {
        return formatDate(new Date());
    }//  w ww .  j  a v a  2  s  .  c o m

    public static String formatDate(Timestamp t) {
        return formatDate(new Date(t.getTime()));
    }

    public static String formatDate(Timestamp t, String pattern) {
        return formatDate(new Date(t.getTime()), STANDARD_DATE_PATTERN);
    }

    public static String formatDate(Date date) {
        return formatDate(date, STANDARD_DATE_PATTERN);
    }

    public static String formatDate(Date date, String pattern) {
        if (date == null)
            return null;
        DateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }
}

Related

  1. currentTime()
  2. CurrentTimeString()
  3. getNowSQLTime()
  4. getNowTime()