我是靠谱客的博主 隐形手套,最近开发中收集的这篇文章主要介绍java 8小时制_java 计算工作日的。8小时制度,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class DayTest {

public static void main(String[]args){

String BeginDate="2014-03-27 13:16:00.000";

String EndDate="2014-03-28 11:46:00.000";

double day = getDay(BeginDate,EndDate);

System.out.println("天数:"+day);

}

private static double getDay(String beginDate, String endDate) {

SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); //这里的格式可以自己设置

//String times = from.format(beginDate);

double JSHH = 0;

double JSDay = 0;

double day = getDD(beginDate,endDate);

System.out.println(day);

if(day<1){

JSHH = getHH(beginDate,endDate);

System.out.println("JSHH = "+JSHH);

if(JSHH%60 != 0){

System.out.println("JSHH/60 = "+JSHH/60);

int a = (int) (JSHH / 60);

System.out.println("a = "+a);

JSHH = a + 0.5;

JSDay = JSHH / 8;

return JSDay;

}else{

JSHH = JSHH / 60 ;

JSDay = JSHH / 8;

return JSDay;

}

}else{

day = getDD(beginDate,endDate);

System.out.println("day:"+day);

JSHH = getHH(getAddDay(beginDate,day),endDate);

System.out.println("JSHH = "+JSHH);

if(JSHH%60 != 0){

System.out.println("JSHH/60 = "+JSHH/60);

int a = (int) (JSHH / 60);

System.out.println("a = "+a);

JSHH = a + 0.5;

}else{

JSHH = JSHH / 60 ;

}

System.out.println("JSHH ="+JSHH);

JSHH = JSHH / 8;

JSDay = day + JSHH;

return JSDay;

}

}

public static double getDD(String time1, String time2){

long quot = 0;

SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");

try {

Date date1 = ft.parse( time1 );

Date date2 = ft.parse( time2 );

quot = date2.getTime() - date1.getTime();

quot = quot / 1000 / 60 / 60 / 24;

} catch (ParseException e) {

e.printStackTrace();

}

return quot;

}

public static double getHH(String time1, String time2){

long quot = 0;

SimpleDateFormat ft = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); //这里的格式可以自己设置

StringBuffer T = new StringBuffer();

T.append(time1.substring(0, 10));

SimpleDateFormat ftHH = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //这里的格式可以自己设置

try {

System.out.println("time1:"+time1);

Date date1 = ft.parse( time1 );

Date date2 = ft.parse( time2 );

Date DateHH1 = ftHH.parse(time1);

Date DateHH2 = ftHH.parse(time2);

System.out.println("DateHH1:"+DateHH1);

System.out.println("DateHH2:"+DateHH2);

if(DateHH1.getTime() >= ftHH.parse(T.toString()+" 8:30:00").getTime() &&

DateHH1.getTime() <= ftHH.parse(T.toString()+" 11:45:00").getTime() &&

DateHH2.getTime() >= ftHH.parse(T.toString()+" 13:15:00").getTime() &&

DateHH2.getTime() <= ftHH.parse(T.toString()+" 18:00:00").getTime()){

System.out.println("执行的是方法一 "+ftHH.parse(T.toString()+" 11:45:00").getTime() +" " + date1.getTime());

quot = ftHH.parse(T.toString()+" 11:45:00").getTime() - date1.getTime()+(date2.getTime()-ftHH.parse(T.toString()+" 13:15:00").getTime());

quot = quot / 1000 / 60 ;

System.out.println("quot = "+quot);

return quot;

}

else if(DateHH1.getTime() >= ftHH.parse(T.toString()+" 8:30:00").getTime() &&

DateHH1.getTime() <= ftHH.parse(T.toString()+" 11:45:00").getTime() &&

DateHH2.getTime() <= ftHH.parse(T.toString()+" 11:45:00").getTime() &&

DateHH2.getTime()>DateHH1.getTime()){

quot = DateHH2.getTime() - date1.getTime();

quot = quot / 1000 / 60 ;

return quot;

}

else if(DateHH1.getTime() >= ftHH.parse(T.toString()+" 13:15:00").getTime() &&

DateHH1.getTime() <= ftHH.parse(T.toString()+" 18:00:00").getTime() &&

DateHH2.getTime() <= ftHH.parse(T.toString()+" 18:00:00").getTime() &&

DateHH2.getTime()>DateHH1.getTime()){

quot = DateHH2.getTime() - date1.getTime();

quot = quot / 1000 / 60 ;

return quot;

}

else if(DateHH1.getTime() >= ftHH.parse(T.toString()+" 13:15:00").getTime() &&

DateHH1.getTime() <= ftHH.parse(T.toString()+" 18:00:00").getTime() &&

DateHH2.getTime() <= ftHH.parse(T.toString()+" 11:45:00").getTime()){

quot = ftHH.parse(T.toString()+" 18:00:00").getTime() - date1.getTime() + (date2.getTime()-ftHH.parse(T.toString()+" 8:30:00").getTime());

if(ftHH.parse(T.toString()+" 13:15:00").getTime() == DateHH1.getTime())

{

quot = 0;

}else{

quot = quot / 1000 / 60;

}

System.out.println("quot = "+ quot);

return quot;

}

} catch (ParseException e) {

e.printStackTrace();

}

return quot;

}

public static String getAddDay(String date, double day) {

SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); //这里的格式可以自己设置

Calendar startDT = Calendar.getInstance();

startDT.setTime(getDate(date));

startDT.add(Calendar.DAY_OF_MONTH,(int) day);

return from.format(startDT.getTime());

}

public static Date getDate(String date){

SimpleDateFormat from = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); //这里的格式可以自己设置

long t;

try {

t = from.parse(date).getTime();

Date d = new Date(t);

return d;

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

}

原文:http://blog.csdn.net/yangying19911113/article/details/24268381

最后

以上就是隐形手套为你收集整理的java 8小时制_java 计算工作日的。8小时制度的全部内容,希望文章能够帮你解决java 8小时制_java 计算工作日的。8小时制度所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部