Java SQL Date Get getDateInput(String prompt)

Here you can find the source of getDateInput(String prompt)

Description

get Date Input

License

Open Source License

Declaration

public static java.sql.Date getDateInput(String prompt) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static java.sql.Date getDateInput(String prompt) throws ParseException {
        String input = getStringInput(prompt);
        Date newDate = new SimpleDateFormat("yyyy-MM-dd").parse(input);
        java.sql.Date SQLDate = new java.sql.Date(newDate.getTime());
        return SQLDate;
    }/*w w w.j  av a2s.c o  m*/

    public static String getStringInput(String prompt) {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(prompt);
        System.out.flush();

        try {
            return input.readLine();
        } catch (Exception exception) {
            return "Error: " + exception.getMessage();
        }
    }
}

Related

  1. getDateFromLong(ResultSet resultSet, int index)
  2. getDateFromResultSet(ResultSet rset, Enum field)
  3. getDateFromRTGSDateString(String iobDate)
  4. getDateFromTimestamp(Timestamp timestamp)
  5. getDateFromYMD(Date ymd)
  6. getDateISO(final String sDate)
  7. getDateNextMonth(java.util.Date current)
  8. getDateOfShortStr(String dateStr)
  9. getDateOfString(long time, String patten)