import java.util.*;
public class TestTime {
/**
* @param args
*/
Timer timer = new Timer();
Calendar c = Calendar.getInstance();
Date date = c.getTime();
public void showTime()
{
System.out.println(date.toLocaleString());
System.out.println(date.getYear());
System.out.println(date.getMonth());
System.out.println(date.getDate());
System.out.println(date.getHours());
System.out.println(date.getMinutes());
System.out.println(date.getSeconds());
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
TestTime tt = new TestTime();
tt.showTime();
}}
运行结果:
2006-4-1 12:10:35
106
3
1
12
10
351 12 10 35这是对的,但是106,3不知是何解,3可能是3月份,106应该是2006,怎么可以把106,3转换成2006 4
public class TestTime {
/**
* @param args
*/
Timer timer = new Timer();
Calendar c = Calendar.getInstance();
Date date = c.getTime();
public void showTime()
{
System.out.println(date.toLocaleString());
System.out.println(date.getYear());
System.out.println(date.getMonth());
System.out.println(date.getDate());
System.out.println(date.getHours());
System.out.println(date.getMinutes());
System.out.println(date.getSeconds());
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
TestTime tt = new TestTime();
tt.showTime();
}}
运行结果:
2006-4-1 12:10:35
106
3
1
12
10
351 12 10 35这是对的,但是106,3不知是何解,3可能是3月份,106应该是2006,怎么可以把106,3转换成2006 4
System.out.println(date.toLocaleString());
System.out.println(date.getYear() + 1900);
System.out.println(date.getMonth() + 1);
System.out.println(date.getDate());
System.out.println(date.getHours());
System.out.println(date.getMinutes());
System.out.println(date.getSeconds());
}2006 是 以1900 为基础的
而月份是从 0-11
还有上面的方法已经不提唱用了。已经被删除,所以最好不要在用