Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static Date convertStringToDateBr(String date) {
        Date result = null;
        if (date.length() == 10) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

            try {
                result = format.parse(date);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        if (date.length() == 23) {

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

            try {
                //Log("afaLog","DATA DO BANCO"+date);
                result = format.parse(date);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            try {
                //Log("afaLog","DATA DO BANCO"+date);
                result = format.parse(date);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return result;
    }
}