I'm trying to do a simple console display in Eclipse and my time and date are coming directly from the computer. For some reason, the year display is only coming out in 3 characters instead of 4, and I have no idea why. Any help would be amazing. Here's the code:
public class InClass3 implements ActionListener
{
static int month, day, year, hour, minute;
public static void Display()
{
int i;
String []Date = new String[3];
String []Hello = new String[3];
String []Time = new String[3];
Date();
Time();
for (i = 0; i < 3; i ++)
{
switch (i)
{
case 0:
Hello[0] = "HELLO WORLD";
Date[0] = month + "/" + day + "/" + year;
Time[0] = hour + ":" + minute;
break;
case 1:
Hello[1] = "hello world";
Date[1] = year + "." + month + "." + day;
if (hour > 12)
{
hour = hour - 12;
Time[1] = hour + ":" + minute + "pm";
}
else
{
Time[1] = hour + ":" + minute + "am";
}
break;
case 2:
Hello[2] = "Hello World";
Date[2] = day + " " + month + " " + year;
Time[2] = hour + ":" + minute;
break;
default: System.out.println("Fatal error occured. Please relaunch this application.");
}
System.out.println(Hello[i] + "\n" + Date[i] + "\n" + Time[i]);
}
}
@SuppressWarnings("deprecation")
public static void Time()
{
Date t = new Date();
hour = t.getHours();
minute = t.getMinutes();
}
@SuppressWarnings("deprecation")
public static void Date()
{
Date d = new Date();
year = d.getYear();
month = d.getMonth();
day = d.getDay();
}
public static void main(String[] args)
{
Display();
}
@Override
public void actionPerformed(ActionEvent arg0)
{
// TODO Auto-generated method stub
}
}
And this is what it's outputting:
HELLO WORLD
3/5/115
14:47
hello world
115.3.5
2:47pm
Hello World
5 3 115
2:47
I would obviously like it to display the 2015 - not the 115. Thanks for any insight.