Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {

    public static void main(String[] args) throws Exception {
        // Declare a date format for parsing
        SimpleDateFormat dateParser = new SimpleDateFormat("h:mm a");

        // Parse the time string
        Date date = dateParser.parse("3:30 PM");

        // Declare a date format for printing
        SimpleDateFormat dateFormater = new SimpleDateFormat("HH:mm");

        // Print the previously parsed time
        System.out.println(dateFormater.format(date));
    }
}