package test;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

public class TestGetSystemTime {
	static Date nowTime = null;

	public static void main(String[] args) {

		// 以下为 Clendar 测试代码
		int yyyy, mm, dd,hh,mmm,ss,wm;
		Calendar c = Calendar.getInstance();
		yyyy = c.get(Calendar.YEAR);
		mm = c.get(Calendar.MONTH) + 1;
		dd = c.get(Calendar.DAY_OF_MONTH);

		hh = c.get(Calendar.HOUR);
		mmm = c.get(Calendar.MINUTE);
		ss = c.get(Calendar.SECOND);
		wm = c.get(Calendar.MILLISECOND);


		System.out.println("year = " + yyyy);
		System.out.println("month = " + mm);
		System.out.println("day = " + dd);

		System.out.println("hh = " + hh);
		System.out.println("mmm = " + mmm);
		System.out.println("ss = " + ss);
		System.out.println("wm = " + wm);


		// 1. System.currentTimeMillis() 获取系统时间的代码
		Timestamp ts = new Timestamp(System.currentTimeMillis());
		String dateStr1 = ts.toString();
		System.out.println("System.currentTimeMillis() = " + dateStr1);
		// 2. date 为获得系统时间的另外一种方法
		Date date = new Date();
		String dateStr2 = new Timestamp(date.getTime()).toString();
		System.out.println(dateStr2);
		// 得到JAVA运行环境的一些基本属性
		System.getProperties().list(System.out);
	}
}




执行结果:


year = 2010


month = 6


day = 8


hh = 6


mmm = 11


ss = 53


wm = 703


System.currentTimeMillis() = 2010-06-08 18:11:53.703


2010-06-08 18:11:53.703


java运行的基本信息略



黑色头发:http://heisetoufa.iteye.com