Invoking System.currentTimeMillis() returns the elapase time in milliseconds since midnight of January 1, 1970. Write a program that displays the date and time.
直接上强制类型转换
import java.util.Date;
import java.util.Scanner;
import java.util.Calendar;
public class Hello
{
public static void main(String[] args)
{
String m[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int year,month,day,hour,minute,second;
long currentTime = System.currentTimeMillis();
Date date =new Date(currentTime);
year=date.getYear()+1900;
month=date.getMonth();
day=date.getDate();
hour=date.getHours();
minute=date.getMinutes();
second=date.getSeconds();
System.out.print("Current date and time is "+m[month]);
System.out.println(" "+day+", "+year+" "+hour+":"+minute+":"+second);
}
}