• java 小时时间就近取整


    /**
    * 时间就近取整
    * 08:00 -> 08:00,
    * 08:20 -> 08:30,
    * 08:30 -> 08:30,
    * 08:45 -> 09:00,
    * 23:56 -> 00:00
    *
    * @param time
    * @return outTime
    */
    public static String getCompleteTime(String time) {
    String hour = "00";//小时
    String minutes = "00";//分钟
    String outTime = "00:00";
    StringTokenizer st = new StringTokenizer(time, ":");
    List<String> inTime = new ArrayList<String>();
    while (st.hasMoreElements()) {
    inTime.add(st.nextToken());
    }
    hour = inTime.get(0).toString();
    minutes = inTime.get(1).toString();
    if (Integer.parseInt(minutes) > 30) {
    hour = (Integer.parseInt(hour) + 1) + "";
    outTime = hour + ":00";
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    try {
    outTime = sdf.format(sdf.parse(outTime));
    } catch (Exception e) {
    e.printStackTrace();
    }
    } else if (Integer.parseInt(minutes) == 00) {
    outTime = hour + ":00";
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    try {
    outTime = sdf.format(sdf.parse(outTime));
    } catch (Exception e) {
    e.printStackTrace();
    }
    } else if (Integer.parseInt(minutes) <= 30 && Integer.parseInt(minutes) != 00) {
    outTime = hour + ":30";
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

    try {
    outTime = sdf.format(sdf.parse(outTime));
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    return outTime;
    }
  • 相关阅读:
    Using zend-paginator in your Album Module
    Using zend-navigation in your Album Module
    Unit Testing a zend-mvc application
    Conclusion
    Forms and actions
    Database and models
    Routing and controllers
    Modules
    Java开发的基础条件:
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 数据库报错
  • 原文地址:https://www.cnblogs.com/zhangheliang/p/12611683.html
Copyright © 2020-2023  润新知