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;

import java.util.Date;
import java.util.Locale;

public class Main {
    public static Date convertStringDateToDate(String date) {
        try {
            if (date != null && date.compareTo("null") != 0 && date.compareTo("") != 0) {
                if (date.length() > 11) {
                    return (Date) new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault()).parse(date);
                } else {
                    return (Date) new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}