Java Hour Calculate getCurrHourDate()

Here you can find the source of getCurrHourDate()

Description

get Curr Hour Date

License

Open Source License

Declaration

public static String getCurrHourDate() 

Method Source Code

//package com.java2s;

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

public class Main {
    public static String getCurrHourDate() {

        Calendar now = Calendar.getInstance();

        String date = getDate(now.getTime(), "yyyy-MM-dd");
        int hour = now.get(Calendar.HOUR_OF_DAY);

        return date + "_" + hour;
    }/*from  w  w  w .j a va 2 s . c o m*/

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. addHour(String now)
  2. addHours(int date, int hours)
  3. addNHours(Date date, int hours)
  4. diffHour(String day1, String day2)
  5. getBothTime(String startTime, int hours)
  6. getDelayEndTime(int hour, String timezone)
  7. getDelayTime(int hour, String date)
  8. getDiffDateTime(int diff, int hours)
  9. getDiffHour(String startTime, String endTime)