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;

public class Main {
    public static Date stringToDate(String dateString, int dbType) {
        SimpleDateFormat dateFormat;
        switch (dbType) {
        case 1: //SQLite format
            dateFormat = new SimpleDateFormat("LLL dd, yyyy h:mm:ss aa");
            break;
        case 2: //MySQL format
            dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            break;
        default:
            dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }

        Date convDate = new Date();
        try {
            convDate = dateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return convDate;
    }
}