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.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.TimeZone;

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

    public static String getDateForHistory(String dateString) {
        String[] shortMonths = new DateFormatSymbols().getShortMonths();

        SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formater = new SimpleDateFormat("dd");
        String month = "";

        parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
        formater.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date date = null;
        try {
            parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
            date = parserSDF.parse(dateString);
            month = shortMonths[date.getMonth()];
        } catch (ParseException e) {
            Log.d(TAG, e.getMessage());
        }

        return month + " " + formater.format(date);
    }
}