Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static void main(String[] args) throws Exception {
        Date birth = null;
        String birthDate = "30-MAR-2012";
        DateFormat formatter = null;
        formatter = new SimpleDateFormat("dd-MMM-yyyy");
        birth = (Date) formatter.parse(birthDate); // birtDate is a string
        if (birth == null) {
            System.out.println("Birth object is still null.");
        } else {
            System.out.println("Default date format " + birth);
            System.out.println("Our SimpleDateFormat " + formatter.format(birth));
            System.out.println("Our SimpleDateFormat with all uppercase " + formatter.format(birth).toUpperCase());
        }
    }
}