Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**
     * convert from 'String' format into 'Date' format
     * @param String sDate
     * @param String dateFormat
     * @return
     */
    @SuppressWarnings("deprecation")
    public static Date StringToDate(String sDate, String dateFormat) {
        Date date = null;

        try {
            DateFormat formatter = new SimpleDateFormat(dateFormat);
            date = formatter.parse(sDate);
        } catch (Exception e) {
            date = new Date(1900, 1, 1);
        }

        return date;
    }
}