Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code> /** * Created with IntelliJ IDEA. * User: S34N * Date: 2013/07/30 * Time: 8:21 AM * To change this template use File | Settings | File Templates. */ //Import the required classes/packages import javax.swing.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class dateInputScan { public static void main(String args[]) { dateInputScan run = new dateInputScan(); run.dateInputScan(); } public void dateInputScan() { //Instantiating variables String lvarStrDateOfTransaction = null; DateFormat formatter = null; Date lvarObjDateOfTransaction = null; //Use one of the following date formats. lvarStrDateOfTransaction = "29/07/2013"; //lvarStrDateOfTransaction = "29-07-2013"; //lvarStrDateOfTransaction = "20130729"; //lvarStrDateOfTransaction = "2013-07-29"; //lvarStrDateOfTransaction = "29/07/2013"; //You can also add your own regex (Regular Expression) if (lvarStrDateOfTransaction.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})")) { formatter = new SimpleDateFormat("dd/MM/yyyy"); } else if (lvarStrDateOfTransaction.matches("([0-9]{2})-([0-9]{2})-([0-9]{4})")) { formatter = new SimpleDateFormat("dd-MM-yyyy"); } else if (lvarStrDateOfTransaction.matches("([0-9]{4})([0-9]{2})([0-9]{2})")) { formatter = new SimpleDateFormat("yyyyMMdd"); } else if (lvarStrDateOfTransaction.matches("([0-9]{4})-([0-9]{2})-([0-9]{2})")) { formatter = new SimpleDateFormat("yyyy-MM-dd"); } else if (lvarStrDateOfTransaction.matches("([0-9]{4})/([0-9]{2})/([0-9]{2})")) { formatter = new SimpleDateFormat("yyyy/MM/dd"); } try { lvarObjDateOfTransaction = formatter.parse(lvarStrDateOfTransaction); JOptionPane.showMessageDialog(null, "Date: " + lvarObjDateOfTransaction); } catch (Exception ex) { //Catch the Exception in case the format is not found. JOptionPane.showMessageDialog(null, ex); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload