初学java(12)

API
java.lang 基础包
java.util 工具包
java.math 数学包
java.io 输入输出包
java.sql 数据库工具包
java.ast 图形化组件包
java.net 网络通讯包
javax.swing 图形化组件包
javax.servlet web组件包

calendar实例代码:

package zy;

import java.util.Calendar;

public class Zy {

	public static void main(String args[]) {
		int a[] = { 10, 12, 213, 31 };
		try {
			System.out.println(a[4]);
		} catch (ArrayIndexOutOfBoundsException b) {
			System.out.print(b.getClass().getSimpleName() + ":");
			System.out.println(b.getMessage());
		}

		Calendar calendar = Calendar.getInstance();
		StringBuffer sb = new StringBuffer();
		char week[] = { '日', '一', '二', '三', '四', '五', '六' };
		sb.append("现在的时间是:");
		sb.append(calendar.get(Calendar.YEAR));
		Zy.jg(sb);
		pd(calendar.get(Calendar.MONTH)+1,sb);
		Zy.jg(sb);
		pd(calendar.get(Calendar.DAY_OF_MONTH),sb);
		Zy.jg(sb);
		sb.append("星期");
		sb.append(week[calendar.get(Calendar.DAY_OF_WEEK) - 1]);
		Zy.jg(sb);
		pd(calendar.get(Calendar.HOUR_OF_DAY),sb);
		Zy.jg(sb);
		pd(calendar.get(Calendar.MINUTE),sb);
		Zy.jg(sb);
		pd(calendar.get(Calendar.SECOND),sb);
		System.out.println(sb);
		System.out.println();

	}

	public static void jl(StringBuffer a) {
		a.append('0');
	}

	public static void jg(StringBuffer a) {
		a.append('-');
	}
	public static void pd(int a,StringBuffer b){
		if(a>=10){
			b.append(a);
		}else{
			b.append("0"+a);
		}
		
		
	}

}

你可能感兴趣的:(学习,代码)