Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private final static String TAG = "DateUtils";
    private static SimpleDateFormat mDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    /**
     * Converts a String to a Date
     *
     * @param dateString that is in format 30/12/2018 14:18
     * @return Date object
     */
    public static Date StringToDate(String dateString) {
        Date result = new Date();
        try {
            result = mDateFormat.parse(dateString);
        } catch (ParseException e) {
            Log.e(TAG, "String " + dateString + " cannot be parsed.");
        }
        return result;
    }
}