I'm struggling to find a solution as to converting seconds into years, months, weeks, hours, minutes, seconds.
Example:
public Time(int inputSeconds) {
int years = 0;
int months = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int seconds = 0;
}
First of all my advice is to change time variable type from int to long.
There are certain method in Date class which will help you to achieve this but remember as of now these methods are deprecated.
import java.util.Date;
import java.util.Random;
class MyTime {
int years;
int months;
int day;
int hours;
int seconds;
public MyTime(long inputSeconds) {
Date d = new Date(inputSeconds);
this.years = d.getYear();
this.months = d.getMonth();
this.day = d.getDay();
this.hours = d.getHours();
this.seconds = d.getSeconds();
}
public static void main(String[] args) {
new MyTime(new Date().getTime()).show();
}
public void show() {
System.out.println("" + years + "");
System.out.println("" + months + "");
System.out.println("" + day + "");
System.out.println("" + hours + "");
System.out.println("" + seconds + "");
}
}