java 将天数转成月,使用Java将一组月份转换为几天

I am trying to make a method where you can enter the arguments of, the current month and the amount of months you want to trace back, and convert all of this into days. For example, if the current month was January and I wanted convert the last 5 months into days the answer would be 153. I have the following information for one to use.

private Calendar cal;

private int currentMonth;

private final int JANUARY = 31;

private final int FEBRUARY = 28;

private final int MARCH = 31;

private final int APRIL = 30;

private final int MAY = 31;

private final int JUNE = 30;

private final int JULY = 31;

private final int AUGUST = 31;

private final int SEPTEMBER = 30;

private final int OCTOBER = 31;

private final int NOVEMBER = 30;

private final int DECEMBER = 31;

public Constructor(){

cal = new GregorianCalendar();

currentMonth = cal.get(Calendar.MONTH);

}

private int convertMonthsToDays(int currentMonth, int months){

int days;

return days;

}

解决方案

Use this code for what you want

package test;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import org.hibernate.Criteria;

import org.hibernate.Session;

import org.hibernate.criterion.Restrictions;

import com.ibm.icu.util.Calendar;

import com.ibm.icu.util.GregorianCalendar;

import com.mPower.fw.dao.ClassMaster;

import com.mPower.fw.impl.DaoServiceIMPL;

import com.mPower.fw.util.hibernateUtil;

public class runT {

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

try{

Calendar calendar = new GregorianCalendar();

int CURRENT_MONTH = 0;

int MONTH_BACK = 5;

int totalDays = 0;

calendar.set(Calendar.MONTH, CURRENT_MONTH);

for(int i=0;i

totalDays += calendar.getMaximum(java.util.Calendar.DAY_OF_MONTH);

calendar.add(Calendar.MONTH, -1);

}

System.out.println(totalDays);

}catch(Exception e){

e.printStackTrace();

}

}

}

use calendar.add(Calendar.MONTH, -1); for Month back.

use calendar.add(Calendar.MONTH, 1); for month forward.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值