计算经过时间范围
来源:互联网 发布:手机淘宝怎么搜店铺名 编辑:程序博客网 时间:2024/04/19 10:12
由于公司业务变更,计算夜间服务费晚上23点–早上5点为夜间服务费时间,按分钟收费,考虑各种情况最后想出简单计算规则
这里写代码片 /** * 分钟计算单位 */ private static final int MINTUS_TIME_UNIT=60000; /** * 天计算单位 */ private static final int DAY_TIME_UNIT=24*3600000; /** * 计算夜间服务时长 * @param startTime * @param timeLenght * @return */ public static int getNightServiceTimeLong(Date startTime,long timeLong){ return getNightServiceTimeLong(startTime,new Date(startTime.getTime()+timeLong)); } /** * 计算夜间服务时长(返回单位分钟) * @param startTime开始时间 * @param endTime 结束时间 * @return */ public static int getNightServiceTimeLong(Date startTime, Date endTime){ long startLong=getDateTimetoLong(startTime); long endLong=getDateTimetoLong(endTime); DateTime startDate=new DateTime(startTime).withTime(5,0,0, 0); DateTime start=new DateTime(startTime).withTime(23,0,0, 0); DateTime end=new DateTime(endTime).withTime(5,0,0, 0); DateTime endDate=new DateTime(endTime).withTime(23,0,0, 0); long startMillis=start.getMillis(); long endMillis=end.getMillis(); int sumMinus=calDayDiffer(startMillis,endDate.getMillis())*360; int startDiffer=calMintusDiffer(startMillis,startLong); if(startDiffer>0){ sumMinus-=startDiffer; } int endDiffer=calMintusDiffer(endMillis,endLong); if(endDiffer<0){ sumMinus+=endDiffer; } int endMany=calMintusDiffer(endDate.getMillis(),endLong); if(endMany>0){ sumMinus+=endMany; } int startMany=calMintusDiffer(startLong,Math.min(startDate.getMillis(),endLong)); if(startMany>0&&startMany<300){ sumMinus+=startMany; } return sumMinus; } private static long getDateTimetoLong(Date date){ return new DateTime(date).withSecondOfMinute(0).withMillisOfSecond(0).getMillis(); } private static int calDayDiffer(long start,long end){ return (int)((end-start)/DAY_TIME_UNIT); } /** * 计算时差 返回单位分钟 * @param start * @param end * @return */ private static int calMintusDiffer(long start,long end){ return (int)((end-start)/MINTUS_TIME_UNIT); }
1 0
- 计算经过时间范围
- js计算当前时间的为年的第几周,以及周对应的时间范围
- 一个日期的扩展函数库包括计算周次和本周时间范围(javascript)
- 一个计算周次和本周时间范围的代码(c#)
- 一个日期的扩展函数库包括计算周次和本周时间范围(javascript)
- 一个计算周次和本周时间范围的代码(c#)
- C#计算时间--按照日期确定第几周 按照第几周确定日期范围
- php时间戳函数实现计算第几周,以及当天所在周的具体日期范围
- NSString 计算显示范围
- 判断时间范围
- Java 时间范围 Util
- Access时间范围查询
- sql判断时间范围
- mysql 时间范围 查询
- SQLServer生成时间范围
- 范围要找个时间记住
- shell 遍历时间范围
- python 获取时间范围
- 什么是robots.txt文件?
- 关于JavaScript调试的十来个小Tips
- 放苹果
- 利用TinyXML读取VOC2012数据集的XML标注文件裁剪出所有人体目标保存为文件
- 计算机组成原理面试知识点总结
- 计算经过时间范围
- 关于JavaScript调试的十来个小Tips
- 获取任意线程调用栈的那些事
- 行驶证查询
- Qt添加库文件和头文件目录(QCreator)
- sgu 194 网络流+有下界+循环流+无源汇
- 进销存软件的实用性你了解吗
- myeclipse导入js/Jquery文件报错,出现红叉或者语法错误
- nginx 知识总结