存档

‘java’ 分类的存档

java 多线程小试

2011年4月18日 没有评论 2,654 views  

public class ThreadTest extends Thread {

	private static Object obje = new Object();

	public void run(){
		synchronized (obje) {
			for(int i=0;i<100;i++){
				try {
					if(i%10==0&&i!=0){
						System.out.println("haha");
						obje.notify();
						obje.wait();
					}
					Thread.sleep(100);
					System.out.println(this.getName()+":"+i);
				}catch (InterruptedException e) {
						e.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) {
		Thread t1 = new ThreadTest();
		Thread t2 = new ThreadTest();
		t1.start();
		t2.start();
	}
}

部分输出结果:
阅读全文…

分类: java 标签: ,

java.text.ParseException: Unparseable date: “2011-11-11 03:03PM”

2011年4月12日 没有评论 6,169 views  

代码如下:

Date date = new Date();
DateFormat f=new SimpleDateFormat("yyyy-MM-dd hh:mma");
String str = "2011-11-11 03:03PM";

try {
	Date dat = f.parse(str);
	System.out.println(dat);
} catch (ParseException e) {
    e.printStackTrace();
}

问题出在PM上,如果是“下午”就没问题了,

所以要把DateFormat f=new SimpleDateFormat(“yyyy-MM-dd hh:mma”);

改为DateFormat f=new SimpleDateFormat(“yyyy-MM-dd hh:mma”,Locale.ENGLISH);

分类: java 标签: