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.Calendar;

import android.util.Log;

public class Main {
    /**
     * Return date in specified format.
     * @param milliSeconds Date in milliseconds
     * @param dateFormat Date format 
     * @return String representing date in specified format
     */
    public static String getDate(long milliSeconds) {
        String dateFormat = "dd/MM/yyyy hh:mm:ss"; //.SSS";
        // Create a DateFormatter object for displaying date in specified format.
        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);

        // Create a calendar object that will convert the date and time value in milliseconds to date. 
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(milliSeconds);

        Log.d("EarthquakeMonitor",
                "Helpers.getDate result => " + milliSeconds + " to " + formatter.format(calendar.getTime()));

        return formatter.format(calendar.getTime());
    }
}