Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.support.annotation.NonNull;
import java.util.Calendar;

public class Main {
    @NonNull
    public static Calendar getCalendar(String date) {
        //Date should be in the format YYYY/MM/DD if not return
        if (date != null && !date.isEmpty() && date.length() == 10) {
            int year = Integer.parseInt(date.substring(0, 4));
            int month = Integer.parseInt(date.substring(5, 7));
            int day = Integer.parseInt(date.substring(8, 10));
            Calendar startingTime = Calendar.getInstance();
            startingTime.set(year, month - 1, day, 0, 0, 0);
            return startingTime;
        }
        return null;
    }
}