Java SQL Date Create getTodayDate()

Here you can find the source of getTodayDate()

Description

get Today Date

License

Open Source License

Declaration

public static String getTodayDate() 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static String getTodayDate() {
        java.util.Date date = new java.util.Date();
        java.util.Date today = new java.sql.Timestamp(date.getTime());
        String todayDate = String.valueOf(today);
        //            temp.substring(0,10)+"."+temp.substring(11,23)
        return todayDate.substring(0, 10) + "-" + todayDate.substring(11, 22);
    }/*from   w w  w  . ja  v  a  2s .  c  o  m*/

    public static Date getTime(String hhmm) {
        if (hhmm != null && hhmm.length() == 4 && isDigit(hhmm)) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm.substring(0, 2)));
            cal.set(Calendar.MINUTE, Integer.parseInt(hhmm.substring(2, 4)));

            return cal.getTime();
        }

        return null;
    }

    private static boolean isDigit(String digitStr) {
        if (digitStr != null) {
            for (int i = 0; i < digitStr.length(); i++)
                if (!Character.isDigit(digitStr.charAt(i)))
                    return false;
        }
        return true;
    }
}

Related

  1. getSysDate()
  2. getSysDate()
  3. getSysdate(String format)
  4. getSysDateGMTToday()
  5. getTodayDate()
  6. getTodaySqlDate()
  7. getTodaySqlDate()