zoukankan      html  css  js  c++  java
  • DateUtils

        /**
         * @param period
         *            分钟数值
         * @return yyyy-MM-dd HH:mm:ss
         */
        public static String getMinuteTime(int period)
        {
            String rtn = "";
            long ticks = System.currentTimeMillis();
         //将时间戳划分为分钟取整,计算。 ticks
    = ((ticks / (period * 60 * 1000)) - 1) * period * 60 * 1000; Date date = new Date(ticks); SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); rtn = fm.format(date); return rtn; }

    啦啦啦

    package com.xindatai.common.util;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class DateUtils {
    
        public static final String DATE_FORMAT_BASE = "yyyy-MM-dd HH:mm:ss";
        public static final String DATE_FORMAT_SNUMBER_DAY = "yyyyMMdd";
    
        /**
         * @param date
         * @return yyyy-MM-dd HH:mm:ss
         */
        public static String getCurrMinuteTime()
        {
            String rtn = "";
            long ticks = System.currentTimeMillis();
            ticks = ((ticks / (1 * 60 * 1000))) * 1 * 60 * 1000;
            Date date = new Date(ticks);
            SimpleDateFormat fm = new SimpleDateFormat(DATE_FORMAT_BASE);
            rtn = fm.format(date);
    
            return rtn;
        }
    
        /**
         * 计算两个时间的时间差,单位为分钟
         * 
         * @param time1
         *            时间格式为:yyyy-MM-dd HH:mm:ss
         * @param time2
         *            时间格式为:yyyy-MM-dd HH:mm:ss
         * @return
         */
        public static int getDiffMinutes(String time1, String time2)
        {
            int val = 0;
            try {
                Date date1 = org.apache.commons.lang3.time.DateUtils.parseDate(time1, DATE_FORMAT_BASE);
                Date date2 = org.apache.commons.lang3.time.DateUtils.parseDate(time2, DATE_FORMAT_BASE);
                Long temp = Math.abs(date1.getTime() / (1000 * 60) - date2.getTime() / (1000 * 60));
                val = temp.intValue();
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return val;
        }
    
        /**
         * @param period
         *            分钟数值
         * @return yyyy-MM-dd HH:mm:ss
         */
        public static String getMinuteTime(int period)
        {
            String rtn = "";
            long ticks = System.currentTimeMillis();
            ticks = ((ticks / (period * 60 * 1000)) - 1) * period * 60 * 1000;
            Date date = new Date(ticks);
            SimpleDateFormat fm = new SimpleDateFormat(DATE_FORMAT_BASE);
            rtn = fm.format(date);
    
            return rtn;
        }
    
        /**
         * @param dateStr
         * @return yyyy-MM-dd HH:mm
         */
        public static Date getDateTimeBystr(String dateStr)
        {
            if (dateStr == null || dateStr.length() == 0) {
                return null;
            }
            SimpleDateFormat fm = new SimpleDateFormat(DATE_FORMAT_BASE);
            try {
                return fm.parse(dateStr);
            } catch (ParseException e) {
                e.printStackTrace();
                return null;
            }
        }
    
        public static String getStringByFormat(Date date, String dateFormatSnumberDay) {
            if (date == null)
                return "";
            SimpleDateFormat fm = new SimpleDateFormat(dateFormatSnumberDay);
            return fm.format(date);
        }
    
        public static void main(String[] args) {
    
            System.out.println(getMinuteTime(5));
        }
    
    }

    啦啦啦

  • 相关阅读:
    php字符串处理函数大全 转
    php http Manual
    HTTP协议详解 百度文库
    PHP获取指定日期的上个月的日期 转
    计算指定日期的前N个月日期
    MySQL之count(*)与count(id)效率比较<转>
    生成器
    可迭代对象_迭代器
    变量内容的删除替换和替代
    软件磁盘阵列
  • 原文地址:https://www.cnblogs.com/ClassNotFoundException/p/6525302.html
Copyright © 2011-2022 走看看