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;

import android.util.Log;

public class Main {
    private final static String TAG = "";

    /**
     * Convert format date
     * @param String date
     * @param String from_format
     * @param String to_format
     * @return
     */
    public static String convertFormatDate(String date, String from_format, String to_format) {
        SimpleDateFormat inputFormat = null;
        SimpleDateFormat outputFormat = null;
        Date formattedDate = null;

        try {
            inputFormat = new SimpleDateFormat(from_format);
            outputFormat = new SimpleDateFormat(to_format);
            formattedDate = inputFormat.parse(date);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

        return outputFormat.format(formattedDate);
    }
}