Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**
     * Convert String date to Date type
     * 
     * @param date
     *            String date
     * @param format
     *            date format
     * @return Date
     */
    public static Date stringToDate(String date, String format) {
        if (date == null)
            return null;
        ParsePosition pos = new ParsePosition(0);
        SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
        Date stringDate = simpledateformat.parse(date, pos);
        return stringDate;

    }
}