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

public class Main {
    @SuppressWarnings("deprecation")
    public static String dateFormat(long stamp) {
        Date date = new Date(stamp * 1000);
        Date today = new Date();

        SimpleDateFormat format;
        if (date.getDate() == today.getDate()) {
            format = new SimpleDateFormat("HH:mm");
        } else if (date.getYear() == today.getYear()) {
            format = new SimpleDateFormat("MM-dd HH:mm");
        } else {
            format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        }

        return format.format(date);
    }
}