「java根据日期分表」java根据开始日期和天数计算结束日期

博主:adminadmin 2022-11-29 12:29:08 50

本篇文章给大家谈谈java根据日期分表,以及java根据开始日期和天数计算结束日期对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Java如何 根据指定的时间段获取时间段内的所有年、季度、月、周。

你的意思是给一个时间跨度好比

2010/3/2-2015/05/06

然后输出 2010 2011 2012 2013 2014 2015 其他类似,是这个意思吗?

String format=new Format("yyyy"),format(new Data());

这样可以获得数字类型的年

Integer int =Integer.parsreInteger(format);

这样可以获得整形的年

之后就是进行循环读取即可。

任意一个起止时间段(如:20160101-20161009),用java将这个时间段拆分成一个个按自然周组成的时间段

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.Scanner;

public class Week {

public static void main(String[] args) throws ParseException {

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

        SimpleDateFormat sdw = new SimpleDateFormat("E");    

        System.out.println("请输入时间段,格式如:20160101-20161111(不足10位以0补足)");

        Scanner s = new Scanner(System.in);

        String date = s.next();

        String begin_date = date.split("-")[0];

        String end_date = date.split("-")[1];

        String begin_date_fm = begin_date.substring(0, 4) + "-" + begin_date.substring(5,6) + "-" + begin_date.substring(7,8);

        String end_date_fm =  end_date.substring(0, 4) + "-" + end_date.substring(5,6) + "-" + end_date.substring(7,8);

        Date b = null;

        Date e = null;

        try {    

            b = sd.parse(begin_date_fm); 

            e = sd.parse(end_date_fm);

        } catch (ParseException ee) {    

            ee.printStackTrace();    

        }

        Calendar rightNow = Calendar.getInstance();

        rightNow.setTime(b);

        Date time = b;

        String year = begin_date_fm.split("-")[0];

        String mon = Integer.parseInt(begin_date_fm.split("-")[1])10?"0"+begin_date_fm.split("-")[1]:begin_date_fm.split("-")[1];

        String day = Integer.parseInt(begin_date_fm.split("-")[2])10?"0"+begin_date_fm.split("-")[2]:begin_date_fm.split("-")[2];

        String timeb = year+mon+day;

        String timee = null;

        while(time.getTime()=e.getTime()){

         rightNow.add(Calendar.DAY_OF_YEAR,1);

         time = sd.parse(sd.format(rightNow.getTime()));

         String timew = sdw.format(time);

         if(("星期一").equals(timew)){

         timeb = (sd.format(time)).replaceAll("-", "");

         }

         if(("星期日").equals(timew) || ("星期七").equals(timew) || time.getTime() == e.getTime()){

         timee = (sd.format(time)).replaceAll("-", "");

         System.out.println(timeb+"-"+timee);

         }

        }

        

}

}

java如何根据日期自动编号

要根据时间生成编号,首先要知道编号的方式,比如只是把时间中的符号去掉可以使用SimpleDateFromat这个类

//其实有很多情况都可以用它解决,只需要改其中的格式

//大概是这样,手写的代码

String bh=new SimpleDateFormate("yyyyMMddHHmmss").format(new Date());

//得到201806061331

如果需要复杂点的,可以使用Calendar这个类,获取需要编号的数据进行编号

Calendar c=Calendar.getInstance();

c.setTime(new Date());

//通过get方法获取具体的值,年、月、日、时、分、秒、星期 等

c.get(Calendar.HOUR_OF_DAY);//获得小时,其他的常量可以在官方API查找,或者百度【Calendar.java常量】

java 按日期分组 算法

直接用SQL语句

select count(id) as 数量,day(date) as 生产日期 from table group by day(date) order by day(czrq)

如果库里不止一个月的数据,那么再加个where条件

java实现日期排序问题

java按文件日期排序方法,下面以对C盘Java目录下文件进行按日期排序为例:

//引用java.io包里的所有类

import java.io.*;

import java.util.*;

public class FileOrder{

//按日期排序

public static void orderByDate(String fliePath) {

   File file = new File(fliePath);

   File[] fs = file.listFiles();

   Arrays.sort(fs,new Comparator File(){

     public int compare(File f1, File f2) {

long diff = f1.lastModified() - f2.lastModified();

if (diff  0)

  return 1;

else if (diff == 0)

  return 0;

else

  return -1;

     }

     public boolean equals(Object obj) {

return true;

     }

     });

     for (int i = fs.length-1; i -1; i--) {

System.out.println(fs[i].getName());

System.out.println(new Date(fs[i].lastModified()));

      }

  }

   public static void main(String args[]){

      orderByDate("c:/java"); //调用方法对c:/java目录下文件按日期排序

      }

}

关于java根据日期分表和java根据开始日期和天数计算结束日期的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。