Java Hour Format getFormattedHoursByMinutes(int minutes)

Here you can find the source of getFormattedHoursByMinutes(int minutes)

Description

get Formatted Hours By Minutes

License

Apache License

Declaration

public static String getFormattedHoursByMinutes(int minutes) 

Method Source Code


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

import org.joda.time.DateTime;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DATE_FORMAT = "yyyy-MM-dd";
    public static final String CMS_DRAW_SEQUENCE_FORMAT = "yyyyMMddHHmmss";

    public static String getFormattedHoursByMinutes(int minutes) {
        return formatDate(new DateTime(startOfToday()).plusMinutes(minutes).toDate(), "H:mm");
    }/*from  w w  w  .  j a v a 2 s .  c o m*/

    public static String formatDate(Date date) {
        return formatDate(date, DATE_FORMAT);
    }

    public static String formatDate(Date date, String dateFormat) {
        try {
            return new SimpleDateFormat(dateFormat).format(date);
        } catch (Exception e) {
            return "";
        }
    }

    public static Date formatDate(String date) {
        return parseDate(date, CMS_DRAW_SEQUENCE_FORMAT);
    }

    public static Date startOfToday() {
        return startOfDay(new Date());
    }

    public static Date parseDate(String date) {
        return parseDate(date, DATE_FORMAT);
    }

    public static Date parseDate(String dateString, String dateFormat) {
        try {
            return new SimpleDateFormat(dateFormat).parse(dateString);
        } catch (Exception e) {
            return null;
        }
    }

    public static Date startOfDay(Date date) {
        return new DateTime(date).dayOfYear().roundFloorCopy().toDate();
    }
}

Related

  1. formatWithAge(Date date, String dateFormat, String suffix)
  2. formatWithSql92Date(Date date)
  3. formatXEP0082Date(Date date)
  4. formatXsdDate (final Date date)
  5. formatXsdDateTime(Date d)
  6. getHHmm()
  7. getHHMM(Date date)
  8. getHHMMSS()
  9. getHHMMSS()