Java Time to String time2String(long time)

Here you can find the source of time2String(long time)

Description

time String

License

Apache License

Declaration

public static String time2String(long time) 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String time2String(long time) {
        SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd HH:mm");
        Calendar toyear = Calendar.getInstance();
        Calendar today = Calendar.getInstance();
        toyear.set(Calendar.MONTH, Calendar.JANUARY);
        toyear.set(Calendar.DATE, 1);
        toyear.set(Calendar.HOUR_OF_DAY, 0);
        toyear.set(Calendar.MINUTE, 0);
        toyear.set(Calendar.SECOND, 0);
        today.set(Calendar.HOUR_OF_DAY, 0);
        today.set(Calendar.MINUTE, 0);
        today.set(Calendar.SECOND, 0);

        if (time > toyear.getTime().getTime() && time < today.getTime().getTime())
            df = new SimpleDateFormat("MM-dd");
        else if (time > today.getTime().getTime())
            df = new SimpleDateFormat("HH:mm");
        return df.format(new Date(time));
    }//from w w  w  .  ja va2 s  .  co  m
}

Related

  1. time2String(Date time)
  2. time2string(double t)
  3. timesAreEqual(Date date1, Date date2)
  4. timeStr(Date _Date)
  5. timeString()
  6. timeString(double time)