java SimpleDateFormat &Calendar


package com.founder.ibatisDemo.dojo;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author XiaoQin
 * 
 */
public class DateTestDemo {

	public static void main(String[] args) throws Exception {
		SimpleDateFormat dateformat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss E");
		SimpleDateFormat dateformat0 = new SimpleDateFormat("yyyy");
		SimpleDateFormat dateformat1 = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss E");
		SimpleDateFormat dateformat2 = new SimpleDateFormat(
				"yyyy MM dd  HH mm ss  E ");
		
		String a0 = dateformat0.format(new Date());
		String a1 = dateformat1.format(new Date());
		String a2 = dateformat2.format(new Date());
		
		System.out.println("  1:" + a0);
		System.out.println("  2:" + a1);
		System.out.println(new Date().getYear() + "");
		System.out.println("  3:" + a2);
		System.out.println("    :" + dateformat.format(new Date()));
		System.out.println("=======================");
		
		Calendar c = Calendar.getInstance();
		c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		Date d1 = new Date(c.getTimeInMillis());
		System.out.println("   :" + dateformat.format(d1));

		c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		Date d2 = new Date(c.getTimeInMillis());
		System.out.println("   :" + dateformat.format(d2));
	}

}