Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import java.text.DateFormat;

import java.util.Date;

public class Main {
    private static Context context;

    /**
     * Formats the given date into a nicer date + time string according to the current locale.
     *
     * @param date Date to format
     * @return Localized, nice version of the given timestamp
     */
    public static String formatDate(Date date) {
        if (date == null)
            return "";
        DateFormat targetDateFormat = android.text.format.DateFormat.getMediumDateFormat(context);
        DateFormat targetTimeFormat = android.text.format.DateFormat.getTimeFormat(context);
        return targetDateFormat.format(date) + " " + targetTimeFormat.format(date);
    }
}