Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static final SimpleDateFormat fmtDate = new SimpleDateFormat("dd.mm.yyyy");
    public static final SimpleDateFormat fmtTimeStamp = new SimpleDateFormat("dd.mm.yyyy HH:mm:ss");
    public static final SimpleDateFormat fmtTime = new SimpleDateFormat("HH:mm:ss");

    private static java.util.Date getParsedDate(String type, String parseAs, String value) throws ParseException {

        String format = type;

        if (parseAs != null && parseAs.trim().length() > 0) {
            format = parseAs;
        }

        if (format.equalsIgnoreCase("date")) {
            return fmtDate.parse(value);
        } else if (format.equalsIgnoreCase("time")) {
            return fmtTime.parse(value);
        } else if (format.equalsIgnoreCase("timestamp")) {
            return fmtTimeStamp.parse(value);
        }

        return null;
    }
}